Mercurial > gnulib
changeset 18314:4d47bb4cebc8
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.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 09 May 2016 08:53:10 -0700 |
parents | 4ad1eccbe21f |
children | 128a555eacb6 |
files | ChangeLog lib/glob.c |
diffstat | 2 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon May 09 09:29:35 2016 +0200 +++ b/ChangeLog Mon May 09 08:53:10 2016 -0700 @@ -1,3 +1,10 @@ +2016-05-12 Paul Eggert <eggert@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 <bruno@clisp.org> Fix undefined behaviour in gettext.h.
--- a/lib/glob.c Mon May 09 09:29:35 2016 +0200 +++ b/lib/glob.c Mon May 09 08:53:10 2016 -0700 @@ -478,7 +478,7 @@ { 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 @@ 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 @@ 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);