From 9c95fc6cbe7cfdf59610fa796c6828737043865c Mon Sep 17 00:00:00 2001 From: ache Date: Wed, 15 Aug 2001 20:10:38 +0000 Subject: Use smarter overflow tests Suggested by: bde --- lib/libc/stdio/fseek.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index d311f7a..c357370 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -45,10 +45,11 @@ static const char rcsid[] = #include "namespace.h" #include #include +#include #include +#include #include #include -#include #include "un-namespace.h" #include "local.h" #include "libc_private.h" @@ -132,7 +133,8 @@ _fseeko(fp, offset, whence) } else if (fp->_flags & __SWR && fp->_p != NULL) curoff += fp->_p - fp->_bf._base; - if (offset > 0 && offset + (off_t)curoff < 0) { + /* curoff always >= 0 */ + if (offset > 0 && curoff > OFF_MAX - offset) { errno = EOVERFLOW; return (EOF); } @@ -194,7 +196,8 @@ _fseeko(fp, offset, whence) else { if (_fstat(fp->_file, &st)) goto dumb; - if (offset > 0 && st.st_size + offset < 0) { + /* st.st_size always >= 0 */ + if (offset > 0 && st.st_size > OFF_MAX - offset) { errno = EOVERFLOW; return (EOF); } -- cgit v1.1