From: Paul Eggert Date: Sun, 31 Aug 2025 14:54:18 +0000 (-0700) Subject: u64: avoid theoretical problem with >64-bit int X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7cc3c035d76931aa03330196730b3cd8cab7833;p=thirdparty%2Fgnulib.git u64: avoid theoretical problem with >64-bit int * lib/u64.h: Include limits.h, for INT_MAX. Use uint64_t only if INT_MAX < UINT64_MAX, to avoid undefined behavior on theoretical platforms where adding two uint64_t expressions can have undefined behavior on signed integer overflow. --- diff --git a/ChangeLog b/ChangeLog index 33d9975bbe..70dc193626 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2025-08-31 Paul Eggert + + u64: avoid theoretical problem with >64-bit int + * lib/u64.h: Include limits.h, for INT_MAX. Use uint64_t only if + INT_MAX < UINT64_MAX, to avoid undefined behavior on theoretical + platforms where adding two uint64_t expressions can have undefined + behavior on signed integer overflow. + 2024-08-25 Bruno Haible nstrftime tests: Test in the UTF-8 environment on native Windows. diff --git a/lib/u64.h b/lib/u64.h index 6ea08969c2..01135057c2 100644 --- a/lib/u64.h +++ b/lib/u64.h @@ -1,4 +1,4 @@ -/* uint64_t-like operations that work even on hosts lacking uint64_t +/* Unsigned integers with arithmetic modulo 2**64 Copyright (C) 2006, 2009-2025 Free Software Foundation, Inc. @@ -22,6 +22,7 @@ #error "Please include config.h first." #endif +#include #include #include @@ -37,7 +38,7 @@ extern "C" { #endif -#ifdef UINT64_MAX +#if defined UINT64_MAX && INT_MAX < UINT64_MAX /* Native implementations are trivial. See below for comments on what these operations do. */ diff --git a/modules/u64 b/modules/u64 index 3a78ce3691..4a7f36157a 100644 --- a/modules/u64 +++ b/modules/u64 @@ -1,5 +1,5 @@ Description: -uint64_t-like operations that work even on hosts lacking uint64_t +Unsigned integers with arithmetic modulo 2**64 Files: lib/u64.h