gpt4 book ai didi

c++ - 错误 :Stack around the variable 'hexStr' was corrupted in c++

转载 作者:行者123 更新时间:2023-11-30 02:03:41 27 4
gpt4 key购买 nike

我想使用 AES 算法。

我用这个功能就可以了

void SubBytes(char *SArr[4][4]){
int r,c;
char xlook[2];char ylook[2]; char hexStr[2]; char *Pad;
int intxlook,intylook;
char *temp;
int subbyte;
Pad = (char *)malloc (sizeof(char));
temp = (char *)malloc (sizeof(char));

for (r = 0; r < 4; r++)
for(c = 0; c < 4; c++){
strcpy(temp,"");
strcpy(xlook,"");strcpy(ylook,"");
strcpy(temp,SArr[r][c]);
xlook[0] = temp[0]; xlook[1] = '\0';
ylook[0] = temp[1];ylook[1] = '\0';
intxlook = string_to_dec(xlook);
intylook = string_to_dec(ylook);

subbyte = SBox(intxlook,intylook);
itoa(subbyte,hexStr,16);

if (strlen(hexStr) < 2){
strcpy(Pad,"");
Pad = Padding(0,1);
strcat(Pad,hexStr);
strcpy(SArr[r][c],Pad);
}
else
strcpy(SArr[r][c],hexStr);

}

//free(temp); free(Pad);
} //end

但是我得到了错误

变量“hexStr”周围的堆栈在 c 中已损坏

最佳答案

您忘记了空终止 hexStr

所以当你执行 strcpy(SAr[r][c],hexStr); 时。它会尝试从 hexStr 复制到 SArr[r][c],直到到达 '\0',这可能在任何地方。

关于c++ - 错误 :Stack around the variable 'hexStr' was corrupted in c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11518303/

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