From a9418e02e6cb59bfa004896c661d949f8b705209 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 24 Jul 2011 09:42:14 -0700 Subject: [PATCH] ftell: do not assume wraparound signed arithmetic * lib/ftell.c: Include . (ftell): Don't assume wraparound signed arithmetic. --- ChangeLog | 4 ++++ lib/ftell.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7b6984cbc0..63c0367648 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,10 @@ 2011-07-24 Paul Eggert + ftell: do not assume wraparound signed arithmetic + * lib/ftell.c: Include . + (ftell): Don't assume wraparound signed arithmetic. + * README: Modernize discussion of signed integers. Assuming overflow wraparound is no longer safe. Mention ones' complement and signed magnitude. diff --git a/lib/ftell.c b/lib/ftell.c index 79083fb496..babba353ba 100644 --- a/lib/ftell.c +++ b/lib/ftell.c @@ -20,6 +20,7 @@ #include #include +#include /* Get off_t. */ #include @@ -28,7 +29,7 @@ ftell (FILE *fp) { /* Use the replacement ftello function with all its workarounds. */ off_t offset = ftello (fp); - if (offset == (long)offset) + if (LONG_MIN <= offset && offset <= LONG_MAX) return (long)offset; else { -- 2.30.2