HEAP corruption on PC with const char*


Posted by Jaime | Posted in Coding | Posted on 30-09-2010

Tags: , ,

I had a weird thing happen where if I create a TCHAR variable[MAX_PATH] and populate that using any Win32 function, then take that variable and memcpy it into a const char * that has been new’d, I get a HEAP corruption message when I call delete[] on the const char *.

Now the funny thing is… if I change out the memcpy for strcpy, the HEAP corruption message goes away in debug mode, however, if I use strncpy, I get the HEAP corruption message again.