segmentation fault in memcpy
Hello everyone,
I am wondering if I met with segmentation fault in memcpy (Red Hat Linux). How to debug it? And what is the possible reason of segmentation fault -- source address error, destination address error or size error? Sorry that my application is too large and I can not post all the codes. thanks in advance, George |
Code:
gcc -g -o myapp myapp Once you know the line add printf statements just before the faulting line, which show all of the values for the arguments to memcpy(). If printf() bombs, then it means the address for the destination or source are invalid, an you can then sprinkle printf's around finding where the pointer problem originated. |
Thanks Jim,
Quote:
What do you mean printf() bombs? You mean printf() cause segmentation fault? Could you recommend some approach or some tools to debug? The buffers (both source and destination) are on heap. regards, George |
Can you post only the source code around this error? Just 10 lines around the line where you got the segfault.
|
Thanks nhydra,
Quote:
Any ideas or comments? Any tools to use to detect errors? Any more information needed to analyze this issue? regards, George |
What is the type of source and dest buffers? Are you sure you have the right pointers in the memory? Wrong address of the pointer can do segfault too.
Another thought... try to copy some data in the destination buffer. This is the info about the memcpy() function Code:
void * memcpy (void *restrict TO, const void *restrict |
Quote:
|
All times are GMT -5. The time now is 09:29 PM. |