]> Savannah Git Hosting - gnulib.git/commitdiff
glob: port better to C23
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 4 Feb 2024 06:06:41 +0000 (22:06 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 4 Feb 2024 06:08:30 +0000 (22:08 -0800)
* lib/glob.c: Include <stdckdint.h>.
(size_add_wrapv): Remove.  All uses replaced by ckd_add.
* modules/glob: Depend on stdckdint.

ChangeLog
lib/glob.c
modules/glob

index 84f91b4fc921b1f5160e64279a780b4b1b23c949..088b866362222270f3fa5a8a314bcd14ba68b13c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2024-02-03  Paul Eggert  <eggert@cs.ucla.edu>
 
+       glob: port better to C23
+       * lib/glob.c: Include <stdckdint.h>.
+       (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
index 8ed63b8aa2b6ca63596be69ca806f060f1c3cc87..dc1a915c054adc436c481ab38ffbd3297a3982cf 100644 (file)
@@ -31,6 +31,7 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <stdckdint.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <assert.h>
@@ -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)
index 7d1fea1d5d38a9e70f154b76d336369a72e6e308..857a9286014cb36775212f843ae9dfe40a2803ba 100644 (file)
@@ -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]