Run-Time Check Failure #2 - Stack around the variable 'hex' was corrupted.

C++程序调度时发现一段代码退出时会有“Run-Time Check Failure #2 - Stack around the variable 'hex' was corrupted.”报错g。在网上找了一些信息,大部分是说由于堆栈溢出导致出错,可是我的代码看起来并没有溢出的情况。有看到网上的暂时规避思路,把hex[2]改为hex[3]就无此问题。原因暂不明确。

string Encrypt(string plaintext) {
ciphertext = "";
char plainchar[12];
char cipherchar[12] = "";
for (unsigned int i = 0; i < plaintext.size(); i += 8) { //把明文按每8个字节分割
strcpy(plainchar, plaintext.substr(i, 8).c_str());
memset(cipherchar, 0, sizeof(cipherchar)); //把cipherchar每一位赋值0
Run(cipherchar, plainchar, true); //获取对应密文
unsigned char buf[8] = {0};
memcpy(buf, cipherchar, 8);
for (int j = 0; j < 8; j++)
{
char hex[2] = {0};//后来改为hex[3]
IntToHex(buf[j], hex);

ciphertext += hex;
}
}

return ciphertext;
}

void IntToHex(int i, char buf[2])//后来改为buf[3]
{
sprintf((char *)buf, "%02x", i);
}

转载于:https://www.cnblogs.com/kamiya/p/11189432.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值