警告C6386-如何避免缓冲区溢出

时间:2020-03-05 11:20:46

标签: c++ warnings

以下代码引发了“缓冲区溢出”警告消息。如果有人通过此代码段识别出问题,将会很有帮助。

int *index;
UINT tasks = 1024;

index = (int*)malloc( tasks * sizeof(int));
for (UINT ixFree = 0; ixFree < tasks; ixFree++)
    index[ixFree] = ixFree; //Warning   C6386   Buffer overrun while writing to 'index':  the writable size is 'tasks*sizeof(int)' bytes, but '8' bytes might be written.

谢谢

0 个答案:

没有答案