Closed seanm closed 9 years ago
That satisfied the complier anyway, and looks correct AFAICT.
There are similar shenanigans in m2util.c, if you care to take a stab:
/libminc/libsrc2/m2util.c:786:17: warning: cast from 'unsigned char *' to 'int *' increases required alignment from 1 to 4 [-Wcast-align]
t = * ( int * ) src_ptr;
^~~~~~~~~~~~~~~~~
These 2 files have many warnings of the form:
Note that 'data' is defined as:
Which means it may be aligned as char (1 byte).
This is not just pedantic, but a real bug that will expose itself on some architectures (I think ex: ARM) where unaligned access is not allowed. i.e. short* must be aligned in memory on the size of short (2 bytes).
One fix would be to use memcpy like:
Another might be to allocate 'data' with malloc() so that at least it's guaranteed to be aligned suitably for anything from char* to double*. This will fix the bug at runtime, but probably not get rid of the warning.
Other ideas?