Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAN_B+pAkjU-fLpiYVkh8p5VYx_dvaM1JYLCksEUkPGdn9oXt4A@mail.gmail.com>
Date: Tue, 24 Jun 2025 17:02:05 +0800
From: Jacob Abrams <satur9nine@...il.com>
To: musl@...ts.openwall.com
Subject: [PATCH] endian.h: use parentheses to silence warnings

It would be nice to silence some warnings that arise from endian.h, for example:

musl/include/endian.h:29:25: warning: '&' within '|' [-Wbitwise-op-parentheses]
   29 |         return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24;
      |                        ~ ~~~~~~^~~~~~~
musl/include/endian.h:29:25: note: place parentheses around the '&'
expression to silence this warning
   29 |         return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24;
      |                                ^
      |                          (            )
musl/include/endian.h:29:41: warning: '&' within '|' [-Wbitwise-op-parentheses]
   29 |         return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24;
      |                                        ~ ~~~~~~^~~~~~~~~
musl/include/endian.h:29:41: note: place parentheses around the '&'
expression to silence this warning
   29 |         return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24;
      |                                                ^
      |                                          (              )
musl/include/endian.h:34:23: warning: operator '<<' has lower
precedence than '+'; '+' will be evaluated first
[-Wshift-op-parentheses]
   34 |         return __bswap32(__x)+0ULL<<32 | __bswap32(__x>>32);
      |                ~~~~~~~~~~~~~~^~~~~~~
musl/include/endian.h:34:23: note: place parentheses around the '+'
expression to silence this warning
   34 |         return __bswap32(__x)+0ULL<<32 | __bswap32(__x>>32);
      |                              ^
      |                (                  )

Note: I'm not subscribed to the mailing-list, so CCs are appreciated
---
 include/endian.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/endian.h b/include/endian.h
index 172c4320..2819c926 100644
--- a/include/endian.h
+++ b/include/endian.h
@@ -18,17 +18,17 @@

 static __inline uint16_t __bswap16(uint16_t __x)
 {
-    return __x<<8 | __x>>8;
+    return (__x<<8) | (__x>>8);
 }

 static __inline uint32_t __bswap32(uint32_t __x)
 {
-    return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24;
+    return (__x>>24) | ((__x>>8)&0xff00) | ((__x<<8)&0xff0000) | (__x<<24);
 }

 static __inline uint64_t __bswap64(uint64_t __x)
 {
-    return __bswap32(__x)+0ULL<<32 | __bswap32(__x>>32);
+    return ((__bswap32(__x)+0ULL)<<32) | __bswap32(__x>>32);
 }

 #if __BYTE_ORDER == __LITTLE_ENDIAN
--
2.50.0

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.