2013-05-09 22:10:05 UTC
I am new to C/C++ development in Netbeans. I encountered following problem.
I am doing some pointer operations in my code n then memcpy() sample code is as follows.
................................
char * dest;
int nValue= toPointer - fromPointer;
dest = malloc(nValue+1);
memset(dest,0,nValue+1);
memcpy(dest,fromPointer,nValue);
dest[nValue]='\0';
...............................
when i am running my application , it is crashing just after memset().
To avoid crash i have done following changes.
1. Value of nValue is always greater than 0 also i have added NULL checks to ensure that fromPointer and dest are not NULL.
2. Instead of memcpy I used for loop to copy the content character by character
With both changes application still crashed with same error message... error message is as follows
/cygdrive/E/Program Files/NetBeans 7.2.1/ide/bin/nativeexecution/dorun.sh: line 33: 2864 segmentation fault sh "${SHFILE}"
Any suggestion to avoid this crash ?