]> Savannah Git Hosting - gnulib.git/commitdiff
glob: don't assume INT_MAX < SIZE_MAX
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 9 May 2016 15:53:10 +0000 (08:53 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 13 May 2016 06:10:57 +0000 (23:10 -0700)
* 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
lib/glob.c

index a8ba38ef7b353daad5b3c22f4a3ab47f0ee556c0..4a51afdaa98c6f18a7274423f45d718344b4be4d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index ff4fee1a41345a6fa73c7ac958719fb81312c38e..51fc4d44f9f1030628317cc8b38fc2b95b274710 100644 (file)
@@ -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);