mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] eliminate strict parentheses warnings for byteswaps
@ 2019-02-15  0:24 Nick Bray
  2019-02-15  1:55 ` A. Wilcox
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Bray @ 2019-02-15  0:24 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 837 bytes --]

Patch is attached.

The change was motivated by including Musl's headers from a project
with -Werror -Wall enabled. I believe Fucshia ran into this, too.  I
couldn't think of a good regression test, in part because warnings are
somewhat compiler specific.  One possible approach would be to enable
-Werror -Wall in the main build, but that runs into issues of which
compilers are supported and what the core developers prefer.  Another
approach would be to only lint the header files - generate a dummy .c
file that includes all the header files and compile it with -Werror.
This is complicated by the "redirection" header files that warn you
should use the canonical version.  Which header files should be
checked?  So for the moment I punted on regression testing.  I mention
this line of thinking in case anyone has some perspective.

[-- Attachment #2: 0001-eliminate-strict-parentheses-warnings-for-byteswaps.patch --]
[-- Type: text/x-patch, Size: 1673 bytes --]

From 347fdeccf9268cefa40b8389790e465a3e2e6587 Mon Sep 17 00:00:00 2001
From: Nick Bray <ncbray@google.com>
Date: Thu, 17 Jan 2019 15:53:46 -0800
Subject: [PATCH] eliminate strict parentheses warnings for byteswaps

adding these parentheses eliminates a warning from -Wparentheses, but
does not change the semantics of the code.
---
 include/byteswap.h | 4 ++--
 include/endian.h   | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/byteswap.h b/include/byteswap.h
index 00b9df3c..928be2b3 100644
--- a/include/byteswap.h
+++ b/include/byteswap.h
@@ -11,12 +11,12 @@ static __inline uint16_t __bswap_16(uint16_t __x)
 
 static __inline uint32_t __bswap_32(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 __bswap_64(uint64_t __x)
 {
-	return __bswap_32(__x)+0ULL<<32 | __bswap_32(__x>>32);
+	return (__bswap_32(__x)+0ULL)<<32 | __bswap_32(__x>>32);
 }
 
 #define bswap_16(x) __bswap_16(x)
diff --git a/include/endian.h b/include/endian.h
index 1bd44451..88c3347b 100644
--- a/include/endian.h
+++ b/include/endian.h
@@ -29,12 +29,12 @@ static __inline uint16_t __bswap16(uint16_t __x)
 
 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.21.0.rc0.258.g878e2cd30e-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-19 22:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-15  0:24 [PATCH] eliminate strict parentheses warnings for byteswaps Nick Bray
2019-02-15  1:55 ` A. Wilcox
2019-02-15  2:27   ` Nick Bray
2019-02-15  2:38     ` Rich Felker
2019-02-19 22:54       ` Nick Bray

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).