From: "Pádraig Brady" <P@draigBrady.com>
To: bug-gnulib@gnu.org
Subject: [PATCH] read-file: reduce max size from SIZE_MAX to PTRDIFF_MAX
Date: Sun, 2 Feb 2020 16:13:21 +0000 [thread overview]
Message-ID: <20200202161321.43027-1-P@draigBrady.com> (raw)
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 | 11 +++++++++++
lib/read-file.c | 10 +++++-----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1e5f94d3c..86f8626d6 100644
--- 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
diff --git a/lib/read-file.c b/lib/read-file.c
index 50bb00f0c..c6f230178 100644
--- a/lib/read-file.c
+++ b/lib/read-file.c
@@ -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)))
{
--
2.24.1
next reply other threads:[~2020-02-02 16:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-02 16:13 Pádraig Brady [this message]
2020-02-02 16:43 ` [PATCH] read-file: reduce max size from SIZE_MAX to PTRDIFF_MAX Bruno Haible
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200202161321.43027-1-P@draigBrady.com \
--to=p@draigbrady.com \
--cc=bug-gnulib@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).