Mercurial > hg > octave-kai > gnulib-hg
changeset 15452:9086fb6c1ded
ftell: do not assume wraparound signed arithmetic
* lib/ftell.c: Include <limits.h>.
(ftell): Don't assume wraparound signed arithmetic.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sun, 24 Jul 2011 09:42:14 -0700 |
parents | 276662233d21 |
children | 173d1d491540 |
files | ChangeLog lib/ftell.c |
diffstat | 2 files changed, 6 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,10 @@ 2011-07-24 Paul Eggert <eggert@cs.ucla.edu> + 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.
--- 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,7 +29,7 @@ { /* 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 {