[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#652356: please use argument-safe bswap macros on all architectures



Source: eglibc

Hi,

(from #595496) please make sure that this passes on all
architectures:

cat >x.c <<'EOF'
#include <stddef.h>
#include <stdint.h>
#include <byteswap.h>

uint32_t
foo(uint32_t *bar, size_t *baz) {
	return (bswap_32(bar[(*baz)++]));
}
EOF
gcc -Wall -c x.c


On amd64 it passes, on m68k it gives:

x.c: In function ‘foo’:
x.c:6:10: warning: operation on ‘*baz’ may be undefined [-Wsequence-point]
x.c:6:10: warning: operation on ‘*baz’ may be undefined [-Wsequence-point]
x.c:6:10: warning: operation on ‘*baz’ may be undefined [-Wsequence-point]

The difference is in /usr/include/$multiarsch/bits/byteswap.h:

#  define __bswap_32(x) \
     (__extension__                                                           \
      ({ register unsigned int __v, __x = (x);                                \
         if (__builtin_constant_p (__x))                                      \
[…]

(amd64) vs. (m68k)

# define __bswap_32(x) \
  __extension__                                                 \
  ({ unsigned int __bswap_32_v;                                 \
     if (__builtin_constant_p (x))                              \
[…]

That is, the amd64 version evaluates the argument only once.

Please ensure all flavours of the bswap macros on all architectures
behave the same; otherwise it’s an introduction to porting issues
that need not be. Porting is joyful enough already ;-)

Thanks in advance,
//mirabilos
-- 
[...] if maybe ext3fs wasn't a better pick, or jfs, or maybe reiserfs, oh but
what about xfs, and if only i had waited until reiser4 was ready... in the be-
ginning, there was ffs, and in the middle, there was ffs, and at the end, there
was still ffs, and the sys admins knew it was good. :)  -- Ted Unangst über *fs



Reply to: