Is memcpy () function repeated?

I call some C ++ functions inside a signal handler, and my program fails with a segmentation error. When I check with gdb, the memcpy () function is where I get SIGSEGV. I would like to know if memcpy () is a reentrant function or not?

+5
source share
5 answers

In all but the most highly deployed platforms, it will be reentrant. You mention SIGSEGV, so I assume this is not one of them. In this case, most likely, memcpy () is not the culprit: this is the caller's error. If you ask memcpy () to copy bad pointers (or bad length), then this will be an error. You can easily do this:

memcpy(NULL, NULL, 123456789);

This will call SIGSEGV and it will tell you that memcpy () called it. Of course, this is not a memcpy fault - it is just what you said. Your signal handler is causing something strange. The return path (in gdb or any other tool that you have) to the caller’s website should show what you called it with. Otherwise, just print the arguments you pass memcpy.

+11
source
+2

, . , , , .

+1

memcpy BADLY, . , - . , / .

0

I think the problem is that you are using an invalid (or remote) pointer as parameters for the memcpy function, please check your code carefully.

Sincerely.

0
source

All Articles