开发者

SIGSEGV memcopy or memmove

I am developing an Android application using NDK. The application blows up with "SIGSEGV" error which I believe a segmen开发者_如何学编程tation fault error.

I looked at my code and I think memcopy and memmove might cause this error. I was wondering if there is a safe way to call these functions.

Also please let me know any well described NDK debugging tutorials or anything related. Thanks in advance.


The rule with those 2 is that you use memcpy when you're copying a block of bytes from one place to another, and the source and destination don't overlap. If they do overlap, you have to use memmove. However, using them incorrectly results in corrupted data, not segfaults. Segfaults happen when you try to read or write to a memory location that is invalid - its analogous to Java's NullPointerException. You want to triple check that you have destination, source and size in the correct order. Beyond that, we'll need to see some code.


You can use Android's "logcat" logging facility within NDK code, so if you need to understand where things are going bad, that can be pretty helpful (unless you're able to run gdb / gdbserver).

It's very possible that memcpy or memmov can cause a SIGSEGV. You need to be sure all your pointers are correct, and the buffer sizes are correct as well. If you make a mistake there, the best that can happen is your SIGSEGV and program crash. On the worse end, you could overwrite other memory in your application and not know until some time later (making it difficult to find the cause of the corruption).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜