]> Savannah Git Hosting - gnulib.git/commitdiff
stdint: Verify the width of 'long long' before using it as int64_t.
authorBruno Haible <bruno@clisp.org>
Mon, 20 May 2024 11:12:50 +0000 (13:12 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 20 May 2024 11:12:50 +0000 (13:12 +0200)
Suggested by Paul Eggert in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-05/msg00315.html>.

* lib/stdint.in.h (gl_int64_t): Verify that the number of bits of
'long long' is 64 before using it.
(gl_uint64_t): Verify that the number of bits of 'unsigned long long'
is 64 before using it.

ChangeLog
lib/stdint.in.h

index 89c5aa69938a7c8a77d56bc74c65120b6dc267b9..433df67c650182fa59ae76191ea5c9ad90ce9e55 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-05-20  Bruno Haible  <bruno@clisp.org>
+
+       stdint: Verify the width of 'long long' before using it as int64_t.
+       Suggested by Paul Eggert in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2024-05/msg00315.html>.
+       * lib/stdint.in.h (gl_int64_t): Verify that the number of bits of
+       'long long' is 64 before using it.
+       (gl_uint64_t): Verify that the number of bits of 'unsigned long long'
+       is 64 before using it.
+
 2024-05-19  Collin Funk  <collin.funk1@gmail.com>
 
        getusershell: Work around musl bugs.
index fea7483b9cc5d463697d99fae9d87a6b2166e261..cd3fbdd9654c693f6500a7ae9a22c24f177dcb20 100644 (file)
@@ -80,7 +80,7 @@
 #define _@GUARD_PREFIX@_STDINT_H
 
 /* Get SCHAR_MIN, SCHAR_MAX, UCHAR_MAX, INT_MIN, INT_MAX,
-   LONG_MIN, LONG_MAX, ULONG_MAX, _GL_INTEGER_WIDTH.  */
+   LONG_MIN, LONG_MAX, ULONG_MAX, CHAR_BIT, _GL_INTEGER_WIDTH.  */
 #include <limits.h>
 
 /* Override WINT_MIN and WINT_MAX if gnulib's <wchar.h> or <wctype.h> overrides
@@ -189,6 +189,10 @@ typedef __int64 gl_int64_t;
 #   define int64_t gl_int64_t
 #   define GL_INT64_T
 #  else
+/* Verify that 'long long' has exactly 64 bits.  */
+typedef _gl_verify_int64_bits[
+        _STDINT_MAX (1, sizeof (long long) * CHAR_BIT, 0ll) >> 31 >> 31 == 1
+        ? 1 : -1];
 #   undef int64_t
 typedef long long int gl_int64_t;
 #   define int64_t gl_int64_t
@@ -210,6 +214,11 @@ typedef unsigned __int64 gl_uint64_t;
 #   define uint64_t gl_uint64_t
 #   define GL_UINT64_T
 #  else
+/* Verify that 'unsigned long long' has exactly 64 bits.  */
+typedef _gl_verify_uint64_bits[
+        _STDINT_MAX (0, sizeof (unsigned long long) * CHAR_BIT, 0ull)
+        >> 31 >> 31 >> 1 == 1
+        ? 1 : -1];
 #   undef uint64_t
 typedef unsigned long long int gl_uint64_t;
 #   define uint64_t gl_uint64_t