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
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <stdckdint.h>
#include <stddef.h>
#include <stdint.h>
#include <assert.h>
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));
}
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)
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]