[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ftell: two minor proposed patches
From: |
Paul Eggert |
Subject: |
ftell: two minor proposed patches |
Date: |
Sun, 24 Jul 2011 01:50:09 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 |
>From 66b4bf9e4933f708a5729f28df5b594c731f9431 Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Sun, 24 Jul 2011 01:44:03 -0700
Subject: [PATCH 1/2] ftell: do not assume wraparound signed arithmetic
* lib/ftell.c: Include <limits.h>.
(ftell): Don't assume wraparound signed arithmetic.
---
ChangeLog | 4 ++++
lib/ftell.c | 5 +++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4571ed4..196a76a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2011-07-24 Paul Eggert <address@hidden>
+ ftell: do not assume wraparound signed arithmetic
+ * lib/ftell.c: Include <limits.h>.
+ (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 79083fb..1e8e3a2 100644
--- a/lib/ftell.c
+++ b/lib/ftell.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <errno.h>
+#include <limits.h>
/* Get off_t. */
#include <unistd.h>
@@ -28,8 +29,8 @@ ftell (FILE *fp)
{
/* Use the replacement ftello function with all its workarounds. */
off_t offset = ftello (fp);
- if (offset == (long)offset)
- return (long)offset;
+ if (LONG_MIN <= offset && offset <= LONG_MAX)
+ return offset;
else
{
errno = EOVERFLOW;
--
1.7.4.4
>From cdacbab7b59b72db82b9cac404c7b884d8cdd682 Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Sun, 24 Jul 2011 01:47:12 -0700
Subject: [PATCH 2/2] ftell: don't include <unistd.h>
* lib/ftell.c: Don't include <unistd.h>. <stdio.h> is now
guaranteed to define off_t, since the ftell module depends on the
stdio module.
---
ChangeLog | 5 +++++
lib/ftell.c | 2 --
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 196a76a..24ae09e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2011-07-24 Paul Eggert <address@hidden>
+ ftell: don't include <unistd.h>
+ * lib/ftell.c: Don't include <unistd.h>. <stdio.h> is now
+ guaranteed to define off_t, since the ftell module depends on the
+ stdio module.
+
ftell: do not assume wraparound signed arithmetic
* lib/ftell.c: Include <limits.h>.
(ftell): Don't assume wraparound signed arithmetic.
diff --git a/lib/ftell.c b/lib/ftell.c
index 1e8e3a2..bd72a2f 100644
--- a/lib/ftell.c
+++ b/lib/ftell.c
@@ -21,8 +21,6 @@
#include <errno.h>
#include <limits.h>
-/* Get off_t. */
-#include <unistd.h>
long
ftell (FILE *fp)
--
1.7.4.4
- ftell: two minor proposed patches,
Paul Eggert <=
- Re: ftell: two minor proposed patches, Bruno Haible, 2011/07/24
- Re: ftell: two minor proposed patches, Paul Eggert, 2011/07/24
- Re: ftell: two minor proposed patches, Bruno Haible, 2011/07/24
- Re: ftell: two minor proposed patches, Paul Eggert, 2011/07/24
- Re: ftell: two minor proposed patches, Jim Meyering, 2011/07/24
- Re: ftell: two minor proposed patches, Bruno Haible, 2011/07/24
- Re: git, rebase, and ChangeLog, Bruno Haible, 2011/07/24