HEAP corruption on PC with const char*

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.

Weird.

Leave a Reply

Your email address will not be published. Required fields are marked *