Security Check Stack overflow compiler GS option
-
Hi I put my ownerdraw code in a C dll upon exiting it I got a Security check stack overflow. I turned the /GS complier option off looked to work fine under VS debugger. The Calling code is MFC C/C++ The DLL is in C Here is the MFC code
CMystatic::CMystatic()
{
width = 0;
mod = LoadLibrary(TEXT("C:\\SYSADATA\\SYSADATA\\x64\\Debug\\SYSADATA.DLL"));
drawptr = (fownerdraw)GetProcAddress(mod, "ownerdraw");
strsize.cx = 0;
strsize.cy = 0;
myexitparm = &exitparm;
}void CMystatic::DrawItem(LPDRAWITEMSTRUCT pdi)
{exitparm.pdi = pdi; exitparm.sizeptr = &strsize; (drawptr)(myexitparm);
}
Here is the C DLL
typedef struct EXITPARM
{
LPDRAWITEMSTRUCT pdi;
SIZE* sizeptr;};
// void ownerdraw(exitparmptr);
typedef struct EXITPARM* exitparmptr;
__declspec(dllexport) void ownerdraw(exitparmptr parmptr);void ownerdraw(exitparmptr parmptr)
{LPDRAWITEMSTRUCT pdi = parmptr->pdi;
// (char*)myexit += 8;
SIZE* mysize = parmptr->sizeptr; -
Hi I put my ownerdraw code in a C dll upon exiting it I got a Security check stack overflow. I turned the /GS complier option off looked to work fine under VS debugger. The Calling code is MFC C/C++ The DLL is in C Here is the MFC code
CMystatic::CMystatic()
{
width = 0;
mod = LoadLibrary(TEXT("C:\\SYSADATA\\SYSADATA\\x64\\Debug\\SYSADATA.DLL"));
drawptr = (fownerdraw)GetProcAddress(mod, "ownerdraw");
strsize.cx = 0;
strsize.cy = 0;
myexitparm = &exitparm;
}void CMystatic::DrawItem(LPDRAWITEMSTRUCT pdi)
{exitparm.pdi = pdi; exitparm.sizeptr = &strsize; (drawptr)(myexitparm);
}
Here is the C DLL
typedef struct EXITPARM
{
LPDRAWITEMSTRUCT pdi;
SIZE* sizeptr;};
// void ownerdraw(exitparmptr);
typedef struct EXITPARM* exitparmptr;
__declspec(dllexport) void ownerdraw(exitparmptr parmptr);void ownerdraw(exitparmptr parmptr)
{LPDRAWITEMSTRUCT pdi = parmptr->pdi;
// (char*)myexit += 8;
SIZE* mysize = parmptr->sizeptr;I never saw such an error/warning in my code. What I see in your code snippet (and it is was I don't like) is this expression:
void ownerdraw(exitparmptr parmptr)
{
LPDRAWITEMSTRUCT pdi = parmptr->pdi;What happens when the function argument parmptr is nullptr? Yes, the program crash!
-
I never saw such an error/warning in my code. What I see in your code snippet (and it is was I don't like) is this expression:
void ownerdraw(exitparmptr parmptr)
{
LPDRAWITEMSTRUCT pdi = parmptr->pdi;What happens when the function argument parmptr is nullptr? Yes, the program crash!