>From 1e75316d5a581ad87d659bd6f4c22153d8640cc0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 5 Dec 2020 11:47:51 +0100 Subject: [PATCH 3/6] fnmatch: Use idx_t for nonnegative ptrdiff_t variables. * lib/fnmatch.c: Include idx.h. In glibc, define idx_t directly. * lib/fnmatch_loop.c (EXT): Mark slen, new_used, plensize as nonnegative. * modules/fnmatch (Depends-on): Add idx. --- ChangeLog | 8 ++++++++ lib/fnmatch.c | 6 ++++++ lib/fnmatch_loop.c | 6 +++--- modules/fnmatch | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d32664..797f6d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2020-12-05 Bruno Haible + fnmatch: Use idx_t for nonnegative ptrdiff_t variables. + * lib/fnmatch.c: Include idx.h. In glibc, define idx_t directly. + * lib/fnmatch_loop.c (EXT): Mark slen, new_used, plensize as + nonnegative. + * modules/fnmatch (Depends-on): Add idx. + +2020-12-05 Bruno Haible + c-stack: Use idx_t for nonnegative ptrdiff_t variables. * lib/c-stack.c: Include idx.h. (die): Mark buflen as nonnegative. diff --git a/lib/fnmatch.c b/lib/fnmatch.c index 3014428..c80809e 100644 --- a/lib/fnmatch.c +++ b/lib/fnmatch.c @@ -76,6 +76,12 @@ extern int fnmatch (const char *pattern, const char *string, int flags); #include #include +#ifdef _LIBC +typedef ptrdiff_t idx_t; +#else +# include "idx.h" +#endif + /* We often have to test for FNM_FILE_NAME and FNM_PERIOD being both set. */ #define NO_LEADING_PERIOD(flags) \ ((flags & (FNM_FILE_NAME | FNM_PERIOD)) == (FNM_FILE_NAME | FNM_PERIOD)) diff --git a/lib/fnmatch_loop.c b/lib/fnmatch_loop.c index d9be16f..c533107 100644 --- a/lib/fnmatch_loop.c +++ b/lib/fnmatch_loop.c @@ -1036,9 +1036,9 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end, struct patternlist *newp; \ size_t plen = (opt == L_('?') || opt == L_('@') \ ? pattern_len : (p - startp + 1UL)); \ - ptrdiff_t slen = FLEXSIZEOF (struct patternlist, str, 0); \ - ptrdiff_t new_used = alloca_used + slen; \ - ptrdiff_t plensize; \ + idx_t slen = FLEXSIZEOF (struct patternlist, str, 0); \ + idx_t new_used = alloca_used + slen; \ + idx_t plensize; \ if (INT_MULTIPLY_WRAPV (plen, sizeof (CHAR), &plensize) \ || INT_ADD_WRAPV (new_used, plensize, &new_used)) \ { \ diff --git a/modules/fnmatch b/modules/fnmatch index f547670..2cb69a7 100644 --- a/modules/fnmatch +++ b/modules/fnmatch @@ -14,6 +14,7 @@ attribute [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1] btowc [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1] builtin-expect [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1] flexmember [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1] +idx [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1] intprops [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1] isblank [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1] iswctype [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1] -- 2.7.4