]> Savannah Git Hosting - gnulib.git/commitdiff
read-file: reduce max size from SIZE_MAX to PTRDIFF_MAX
authorPádraig Brady <P@draigBrady.com>
Sun, 2 Feb 2020 16:06:48 +0000 (16:06 +0000)
committerPádraig Brady <P@draigBrady.com>
Sun, 2 Feb 2020 16:52:48 +0000 (16:52 +0000)
On x86_64 with glibc-2.30, gcc 9.2 is giving:
  error: argument 2 value '18446744073709551615'
  exceeds maximum object size 9223372036854775807
  [-Werror=alloc-size-larger-than=]
The details of this restriction are discussed at:
https://stackoverflow.com/q/42574890/4421
* lib/read-file.c: s/SIZE_MAX/PTRDIFF_MAX/

ChangeLog
lib/read-file.c

index 1e5f94d3c89b931f1184eff22795fb1e4d3df7b1..86f8626d680bff8c0c20919e983700b261b0ab0a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2020-02-02  Pádraig Brady  <P@draigBrady.com>
+
+       read-file: reduce max size from SIZE_MAX to PTRDIFF_MAX
+       On x86_64 with glibc-2.30, gcc 9.2 is giving:
+         error: argument 2 value '18446744073709551615'
+         exceeds maximum object size 9223372036854775807
+         [-Werror=alloc-size-larger-than=]
+       The details of this restriction are discussed at:
+       https://stackoverflow.com/q/42574890/4421
+       * lib/read-file.c: s/SIZE_MAX/PTRDIFF_MAX/
+
 2020-02-02  Pádraig Brady  <P@draigBrady.com>
 
        sysctl.h: avoid including on glibc
index 50bb00f0cd87fbbafc2c76967da5a028d18390e4..c6f230178cfc9777338c4319c1d6db0637cf8bc4 100644 (file)
@@ -25,7 +25,7 @@
 /* Get ftello.  */
 #include <stdio.h>
 
-/* Get SIZE_MAX.  */
+/* Get PTRDIFF_MAX.  */
 #include <stdint.h>
 
 /* Get malloc, realloc, free. */
@@ -59,7 +59,7 @@ fread_file (FILE *stream, size_t *length)
             off_t alloc_off = st.st_size - pos;
 
             /* '1' below, accounts for the trailing NUL.  */
-            if (SIZE_MAX - 1 < alloc_off)
+            if (PTRDIFF_MAX - 1 < alloc_off)
               {
                 errno = ENOMEM;
                 return NULL;
@@ -107,16 +107,16 @@ fread_file (FILE *stream, size_t *length)
         {
           char *new_buf;
 
-          if (alloc == SIZE_MAX)
+          if (alloc == PTRDIFF_MAX)
             {
               save_errno = ENOMEM;
               break;
             }
 
-          if (alloc < SIZE_MAX - alloc / 2)
+          if (alloc < PTRDIFF_MAX - alloc / 2)
             alloc = alloc + alloc / 2;
           else
-            alloc = SIZE_MAX;
+            alloc = PTRDIFF_MAX;
 
           if (!(new_buf = realloc (buf, alloc)))
             {