From 8863cab5b9865b1c021704f02da93f0c3d4afbce Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 3 Feb 2024 22:06:41 -0800 Subject: [PATCH] glob: port better to C23 * lib/glob.c: Include . (size_add_wrapv): Remove. All uses replaced by ckd_add. * modules/glob: Depend on stdckdint. --- ChangeLog | 5 +++++ lib/glob.c | 20 +++----------------- modules/glob | 1 + 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 84f91b4fc9..088b866362 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2024-02-03 Paul Eggert + glob: port better to C23 + * lib/glob.c: Include . + (size_add_wrapv): Remove. All uses replaced by ckd_add. + * modules/glob: Depend on stdckdint. + ctime: fix false positive Problem reported by Bjarni Ingi Gislason in: https://lists.gnu.org/r/bug-gnulib/2024-02/msg00006.html diff --git a/lib/glob.c b/lib/glob.c index 8ed63b8aa2..dc1a915c05 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -218,26 +219,11 @@ glob_lstat (glob_t *pglob, int flags, const char *fullname) AT_SYMLINK_NOFOLLOW)); } -/* Set *R = A + B. Return true if the answer is mathematically - incorrect due to overflow; in this case, *R is the low order - bits of the correct answer. */ - -static bool -size_add_wrapv (size_t a, size_t b, size_t *r) -{ -#if 7 <= __GNUC__ && !defined __ICC - return __builtin_add_overflow (a, b, r); -#else - *r = a + b; - return *r < a; -#endif -} - static bool glob_use_alloca (size_t alloca_used, size_t len) { size_t size; - return (!size_add_wrapv (alloca_used, len, &size) + return (!ckd_add (&size, alloca_used, len) && __libc_use_alloca (size)); } @@ -1319,7 +1305,7 @@ glob_in_dir (const char *pattern, const char *directory, int flags, size_t patlen = strlen (pattern); size_t fullsize; bool alloca_fullname - = (! size_add_wrapv (dirlen + 1, patlen + 1, &fullsize) + = (!ckd_add (&fullsize, dirlen + 1, patlen + 1) && glob_use_alloca (alloca_used, fullsize)); char *fullname; if (alloca_fullname) diff --git a/modules/glob b/modules/glob index 7d1fea1d5d..857a928601 100644 --- a/modules/glob +++ b/modules/glob @@ -29,6 +29,7 @@ opendir [test $HAVE_GLOB = 0 || test $REPLACE_GLOB = 1] readdir [test $HAVE_GLOB = 0 || test $REPLACE_GLOB = 1] glibc-internal/scratch_buffer [test $HAVE_GLOB = 0 || test $REPLACE_GLOB = 1] stdbool [test $HAVE_GLOB = 0 || test $REPLACE_GLOB = 1] +stdckdint [test $HAVE_GLOB = 0 || test $REPLACE_GLOB = 1] stdint [test $HAVE_GLOB = 0 || test $REPLACE_GLOB = 1] strdup [test $HAVE_GLOB = 0 || test $REPLACE_GLOB = 1] unistd [test $HAVE_GLOB = 0 || test $REPLACE_GLOB = 1] -- 2.39.5