summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/ftell.c
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2001-08-31 19:50:25 +0000
committerache <ache@FreeBSD.org>2001-08-31 19:50:25 +0000
commit7d962c74f05d15237307926c3a50627b99db7e0b (patch)
tree03e8d35d661564b0014d83106e783bad71d87258 /lib/libc/stdio/ftell.c
parentf00df8355cfea7364defb72e3d4e7d06a7fe52d4 (diff)
downloadFreeBSD-src-7d962c74f05d15237307926c3a50627b99db7e0b.zip
FreeBSD-src-7d962c74f05d15237307926c3a50627b99db7e0b.tar.gz
Disallow ungetc at offset 0 (to prevent negative offset happens), so simplify
checks in ftell.
Diffstat (limited to 'lib/libc/stdio/ftell.c')
-rw-r--r--lib/libc/stdio/ftell.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c
index 93f1f9e..a0b5fa8 100644
--- a/lib/libc/stdio/ftell.c
+++ b/lib/libc/stdio/ftell.c
@@ -116,35 +116,24 @@ get_real_pos:
*/
pos -= fp->_r;
if (pos < 0) {
- if (HASUB(fp)) {
- fp->_p -= pos;
- fp->_r += pos;
- pos = 0;
- } else {
+ fp->_p = fp->_bf._base;
+ fp->_r = 0;
+ if (HASUB(fp))
+ FREEUB(fp);
+ if (spos == -1)
+ goto get_real_pos;
+ pos = spos;
+ } else if (HASUB(fp)) {
+ pos -= fp->_ur;
+ if (pos < 0) {
fp->_p = fp->_bf._base;
fp->_r = 0;
+ FREEUB(fp);
if (spos == -1)
goto get_real_pos;
pos = spos;
}
}
- if (HASUB(fp)) {
- pos -= fp->_ur;
- if (pos < 0) {
- if (-pos <= fp->_r) {
- fp->_p -= pos;
- fp->_r += pos;
- pos = 0;
- } else {
- fp->_p = fp->_bf._base;
- fp->_r = 0;
- FREEUB(fp);
- if (spos == -1)
- goto get_real_pos;
- pos = spos;
- }
- }
- }
} else if ((fp->_flags & __SWR) && fp->_p != NULL) {
/*
* Writing. Any buffered characters cause the
OpenPOWER on IntegriCloud