bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH] glob: port better to C23
@ 2024-02-04  6:08 Paul Eggert
  0 siblings, 0 replies; only message in thread
From: Paul Eggert @ 2024-02-04  6:08 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Paul Eggert

* lib/glob.c: Include <stdckdint.h>.
(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  <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
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 <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)
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.40.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-04  6:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-04  6:08 [PATCH] glob: port better to C23 Paul Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).