C++ error: heap corruption detected:after normal block(#xxx) at 0x xxxxxxxx

来源:互联网 发布:数据录入 编辑:程序博客网 时间:2024/05/16 15:02

This error can occur when deleting or freeing a memory block whose content is longer than its size, that is memory overflow.

example 1:

      
    char*test=(char*)malloc(5);
    strcpy(test,"hello");
    free(test);


example 2:

    char*test=newchar[5];
    strcpy(test,"hello");
    delete test;