]> Savannah Git Hosting - gnulib.git/commitdiff
stddef-tests: port to SIZE_MAX <= INT_MAX
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 9 Feb 2017 00:41:39 +0000 (16:41 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 9 Feb 2017 00:42:05 +0000 (16:42 -0800)
* tests/test-stddef.c: Include <limits.h>, for INT_MAX.
Do not assume that INT_MAX < SIZE_MAX.

ChangeLog
tests/test-stddef.c

index eec777f7d5eb2c67edc2621f81f97a773b92efca..30525490fdf22eeaeff4faad69e0ac89db48b314 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-02-08  Paul Eggert  <eggert@cs.ucla.edu>
+
+       stddef-tests: port to SIZE_MAX <= INT_MAX
+       * tests/test-stddef.c: Include <limits.h>, for INT_MAX.
+       Do not assume that INT_MAX < SIZE_MAX.
+
 2017-02-01  Bruno Haible  <bruno@clisp.org>
 
        lock tests: Fix link error.
index 5b0f0458772c2529b86e98a66107e57d3e1b32a9..8bf3793015c80d7d68b00306934d0367a1386457 100644 (file)
@@ -19,6 +19,7 @@
 #include <config.h>
 
 #include <stddef.h>
+#include <limits.h>
 #include <stdalign.h>
 #include "verify.h"
 
@@ -43,9 +44,12 @@ struct d
    unlikely to bite real code, we ignore that short-coming.  */
 /* verify (sizeof offsetof (struct d, e) == sizeof (size_t)); */
 verify (sizeof (offsetof (struct d, e)) == sizeof (size_t));
-verify (offsetof (struct d, e) < -1); /* Must be unsigned.  */
 verify (offsetof (struct d, f) == 1);
 
+/* offsetof promotes to an unsigned integer if and only if sizes do
+   not fit in int.  */
+verify ((offsetof (struct d, e) < -1) == (INT_MAX < (size_t) -1));
+
 /* Check max_align_t's alignment.  */
 verify (alignof (double) <= alignof (max_align_t));
 verify (alignof (int) <= alignof (max_align_t));