gpt4 book ai didi

c++ - 只有当 len < 3 时,我才会收到堆损坏错误。怎么会?

转载 作者:行者123 更新时间:2023-11-30 01:22:49 26 4
gpt4 key购买 nike

<分区>

出于某种原因,如果 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;

有 isMapNameLegal。顺便说一句,它是静态的:

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;
}

您知道腐败问题的根源吗?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com