diff options
author | ache <ache@FreeBSD.org> | 2001-08-31 19:50:25 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2001-08-31 19:50:25 +0000 |
commit | 7d962c74f05d15237307926c3a50627b99db7e0b (patch) | |
tree | 03e8d35d661564b0014d83106e783bad71d87258 | |
parent | f00df8355cfea7364defb72e3d4e7d06a7fe52d4 (diff) | |
download | FreeBSD-src-7d962c74f05d15237307926c3a50627b99db7e0b.zip FreeBSD-src-7d962c74f05d15237307926c3a50627b99db7e0b.tar.gz |
Disallow ungetc at offset 0 (to prevent negative offset happens), so simplify
checks in ftell.
-rw-r--r-- | lib/libc/stdio/ftell.c | 33 | ||||
-rw-r--r-- | lib/libc/stdio/ungetc.c | 4 |
2 files changed, 15 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 diff --git a/lib/libc/stdio/ungetc.c b/lib/libc/stdio/ungetc.c index f70fb42..092debd 100644 --- a/lib/libc/stdio/ungetc.c +++ b/lib/libc/stdio/ungetc.c @@ -132,6 +132,10 @@ __ungetc(int c, FILE *fp) } fp->_flags |= __SRD; } + + if (!(fp->_flags & __SSTR) && _ftello(fp) == 0) + return (EOF); + c = (unsigned char)c; /* |