[sldev] [VWR] OpenJPEG backtraces (Robin Cornelius)
Argent Stonecutter
secret.argent at gmail.com
Sat Sep 22 06:25:40 PDT 2007
> h.mem = v.mem = (int*)( (unsigned)m + 16 - ( (unsigned)m % 16 ) ) ;
Ick.
Try this:
h.mem = v.mem = (int*)( (char *)m + 16 - ( (char *)m % 16 ) ) ;
There's possibly a derived type that is more "ANSI", but this is
valid portable C.
In addition, I'm not sure that this code is doing the right thing. It
seems to be an attempt to round a pointer up to the next 16 byte
boundary, but where the pointer is already pointing to a 16 byte
boundary is it really supposed to increment it to the next boundary?
If this is just making sure there's room for some specifically
aligned objects below the pointer it will introduce unnecessary 16
byte gaps in the result.
May I suggest (int *)( ((char *) m + 0x10) & ~0x0F ) to round up to
the next 16-byte boundary even if you're on a 16-byte boundary, or
(int *)( ((char *) m + 0x0F) & ~0x0F ) to just round up to the next
16-byte boundary.
Finally, the original code is amusing because the "unsigned" type was
introduced to C because people were having to cast ints to pointers
to get unsigned arithmetic. Since this is arithmetic on pointers to
begin with... :)
More information about the SLDev
mailing list