From: Paul Eggert Date: Mon, 9 May 2016 15:53:10 +0000 (-0700) Subject: glob: don't assume INT_MAX < SIZE_MAX X-Git-Tag: v1.0~6744 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=e4cee3c7310106621ecf00824f75d98ce721746e;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index a8ba38ef7b..4a51afdaa9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-05-12 Paul Eggert + + 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 Fix undefined behaviour in gettext.h. diff --git a/lib/glob.c b/lib/glob.c index ff4fee1a41..51fc4d44f9 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);