Disallow ungetc at offset 0 (to prevent negative offset happens), so simplify

checks in ftell.
This commit is contained in:
Andrey A. Chernov 2001-08-31 19:50:25 +00:00
parent 7cf30ace84
commit 4db40fd143
2 changed files with 15 additions and 22 deletions

View File

@ -116,35 +116,24 @@ _ftello(fp)
*/
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

View File

@ -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;
/*