出于某种原因,如果 len<3,我将在 delete[] 缓冲区行收到堆损坏错误。
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case ID_BUTTON_OK:
{
int len = SendMessage(mapName, WM_GETTEXTLENGTH, 0, 0);
char* buffer = new char[len+1];
ZeroMemory(buffer,sizeof(buffer));
len = SendMessage(mapName, WM_GETTEXT, (WPARAM)len+1, (LPARAM)buffer);
if(isMapNameLegal(buffer)) // Makes sure the map name is legal
{
}
else
{
MessageBox(NULL,"The map name is illegal","Error",MB_ICONERROR);
}
delete[] buffer;
}
break;
有MapNameLegal。顺便说一下,它是静态的:
bool Creator::isMapNameLegal(char* name)
{
if(strlen(name)<=3)
return false;
int x=0;
while(name[x]!='\0')
{
if(name[x]<48 && name[x]!=32) //32=='\r', 48==0,
return false;
if(name[x]>57 && name[x]<65) //57==9, 65==A
return false;
if(name[x]>90 && name[x]<97) //90==Z, 97==a
return false;
if(name[x]>122) //122==z
return false;
x++;
}
return true;
}
你知道腐败问题是从哪里来的吗?