[Bug 4405] expressions in include/archive.h (XZ magic) are undefined on big-endian architectures
bugzilla at busybox.net
bugzilla at busybox.net
Sun Oct 30 19:55:18 UTC 2011
https://bugs.busybox.net/show_bug.cgi?id=4405
--- Comment #1 from Denys Vlasenko <vda.linux at googlemail.com> 2011-10-30 19:55:16 UTC ---
(In reply to comment #0)
> This place in particular:
>
> XZ_MAGIC1a = 256 * (256 * (256 * 0xfd + '7') + 'z') + 'X',
>
> it depends on the signedness of char datatype (all char constants here).
How exactly it depends on signedness of char?
> Compiler produces the following warning:
>
> In file included from archival/ar.c:31:0:
> include/archive.h:17:20: warning: integer overflow in expression [-Woverflow]
> CC archival/bbunzip.o
The warning appears because 0xfd,'7','z','X' as 32-bit big endian constant is
0xfd377a58, which is negative if interpreted as signed value.
IOW: in the last multiply step "256 * (...)" arithmetic overflow occurs:
positive value 0xfd377a gets multiplied by 0x100 and result overflows - becomes
negative value 0xfd377a00.
> Why not use computed numbers for all these magic numbers instead of
> expressions, like
>
> XZ_MAGIC1a = 0xFD377A58UL
Because it's harder to verify that the magic is correct.
Does
XZ_MAGIC1a = 256 * (unsigned)(256 * (256 * 0xfd + '7') + 'z') + 'X'
work on big endian?
--
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the busybox-cvs
mailing list