SIGBUS on ( double * )

Jeffrey Walton noloader at gmail.com
Wed Oct 23 17:45:47 UTC 2013


> I often get SIGBUS when my code (qgis.org) hits stuff like this:
>
> GEOSCoordSeq_getX( cs, j, ( double * )&mGeometry[position] );
Yes, that's not legal C/C++. Its undefined behavior.

> double a;
> memcpy( a, &mGeometry[position])
> GEOSCoordSeq_getX( cs, j, &a )
>
> then all works correctly,
Yep. And if the buffers overlap, you need to `memmov` it.

> could this be because of a
> compiler setting?
No, its the QT devs doing something they should not be doing. Newer
ARMs are OK with unaligned data, while older ARMs are not. They appear
to be testing on newer ARMs only (ARMv6 or ARMv7, IIRC).

I believe -Wstrict-aliasing or -Wcast-align will catch it at compile
time. See http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html and
https://www.gnu.org/software/gsl/manual/html_node/GCC-warning-options-for-numerical-programs.html#GCC-warning-options-for-numerical-programs.

Jeff

On Wed, Oct 23, 2013 at 1:12 PM, Marco Bernasocchi
<marco at bernawebdesign.ch> wrote:
> Hi all, I often get SIGBUS when my code (qgis.org) hits stuff like this:
>
> GEOSCoordSeq_getX( cs, j, ( double * )&mGeometry[position] );
>
> if I change the call to use memcpy like
>
> double a;
> memcpy( a, &mGeometry[position])
> GEOSCoordSeq_getX( cs, j, &a )
>
> then all works correctly, the issue is that I've a lot of those calls and If
> I'm not wrong in the past it used to work). could this be because of a
> compiler setting? I'm using necessitas Qt sdk with ndk r8b1 compiling both
> with -mthumb and without has the same issue.
>
> thanks a lot
> Marco


More information about the Necessitas-devel mailing list