bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] xalloc: avoid GCC 5.1 warning on 32 bit


From: Pádraig Brady
Subject: [PATCH] xalloc: avoid GCC 5.1 warning on 32 bit
Date: Fri, 2 Oct 2015 20:24:46 +0100

* lib/xalloc.h: Disable -Wstrict-overflow for uses of
xalloc_oversized(), which was seen to give this warning
on GCC 5.1 on 32 bit: "assuming signed overflow does not occur
when simplifying conditional".
---
 ChangeLog    |  8 ++++++++
 lib/xalloc.h | 10 ++++++++++
 2 files changed, 18 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 1fe13e2..116bcba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2015-10-02  Pádraig Brady  <address@hidden>
+
+       xalloc: avoid GCC 5.1 warning on 32 bit
+       * lib/xalloc.h: Disable -Wstrict-overflow for uses of
+       xalloc_oversized(), which was seen to give this warning
+       on GCC 5.1 on 32 bit: "assuming signed overflow does not occur
+       when simplifying conditional".
+
 2015-10-02  Daiki Ueno  <address@hidden>
 
        uniname/uniname-tests: avoid compiler warnings
diff --git a/lib/xalloc.h b/lib/xalloc.h
index 81ef680..b250e2d 100644
--- a/lib/xalloc.h
+++ b/lib/xalloc.h
@@ -94,6 +94,12 @@ char *xstrdup (char const *str)
 #define XCALLOC(n, t) \
    ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
 
+/* GCC 5.1 gives an erroneous warning on 32 bit for xalloc_oversized():
+   "assuming signed overflow does not occur when simplifying conditional".  */
+#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wstrict-overflow"
+#endif
 
 /* Allocate an array of N objects, each with S bytes of memory,
    dynamically, with error checking.  S must be nonzero.  */
@@ -121,6 +127,10 @@ xnrealloc (void *p, size_t n, size_t s)
   return xrealloc (p, n * s);
 }
 
+#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
+# pragma GCC diagnostic pop
+#endif
+
 /* If P is null, allocate a block of at least *PN such objects;
    otherwise, reallocate P so that it contains more than *PN objects
    each of S bytes.  S must be nonzero.  Set *PN to the new number of
-- 
2.5.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]