I have a piece of code which works well in debug mode in visual studio but crashes in release mode. After a lot of guess work, i found the piece of code which is causing the crash.
char *buff ="some random text";
char *temp = NULL;
char *pos = NULL;
int len = strlen("random text");
pos = strstr(buff,"random");
temp = (char *) malloc(len+1);
memset(temp,0,len+1);
memcpy(temp,pos,len);
This works perfectly in debug mode, but crashes in release. Could any one point out the error ?