Discussion:
[PATCH] stddef-tests: port to SIZE_MAX <= INT_MAX
(too old to reply)
Paul Eggert
2017-02-09 00:42:20 UTC
Permalink
Raw Message
* tests/test-stddef.c: Include <limits.h>, for INT_MAX.
Do not assume that INT_MAX < SIZE_MAX.
---
ChangeLog | 6 ++++++
tests/test-stddef.c | 6 +++++-
2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index eec777f..3052549 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-02-08 Paul 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 <***@clisp.org>

lock tests: Fix link error.
diff --git a/tests/test-stddef.c b/tests/test-stddef.c
index 5b0f045..8bf3793 100644
--- a/tests/test-stddef.c
+++ b/tests/test-stddef.c
@@ -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));
--
2.9.3
Loading...