* lib/glob.c (glob): Prefer SIZE_MAX to ~((size_t) 0), as the latter is not portable to (probably theoretical) hosts where SIZE_MAX <= INT_MAX. --- ChangeLog | 7 +++++++ lib/glob.c | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog index a8ba38e..4a51afd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-05-12 Paul Eggert <egg...@cs.ucla.edu> + + glob: don't assume INT_MAX < SIZE_MAX + * lib/glob.c (glob): Prefer SIZE_MAX to ~((size_t) 0), as the + latter is not portable to (probably theoretical) hosts where + SIZE_MAX <= INT_MAX. + 2016-05-09 Bruno Haible <br...@clisp.org> Fix undefined behaviour in gettext.h. diff --git a/lib/glob.c b/lib/glob.c index ff4fee1..51fc4d4 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -478,7 +478,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), { size_t i; - if (pglob->gl_offs >= ~((size_t) 0) / sizeof (char *)) + if (pglob->gl_offs >= SIZE_MAX / sizeof (char *)) return GLOB_NOSPACE; pglob->gl_pathv = malloc ((pglob->gl_offs + 1) * sizeof (char *)); @@ -1028,7 +1028,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), char **new_gl_pathv; if (newcount > UINTPTR_MAX - (1 + 1) - || newcount + 1 + 1 > ~((size_t) 0) / sizeof (char *)) + || newcount + 1 + 1 > SIZE_MAX / sizeof (char *)) { nospace: free (pglob->gl_pathv); @@ -1181,7 +1181,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), char **new_gl_pathv; if (newcount > UINTPTR_MAX - 2 - || newcount + 2 > ~((size_t) 0) / sizeof (char *)) + || newcount + 2 > SIZE_MAX / sizeof (char *)) { nospace2: globfree (&dirs); -- 2.5.5