aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2023-11-07 14:16:13 +0000
committerEd Maste <emaste@FreeBSD.org>2023-11-07 18:41:55 +0000
commit0b7939d725ba0ca903c5f8a3ca6d74347eb88690 (patch)
tree8fa89361d69837ac1357dd8a8c3bcb255610a46b
parent59ec3ffdd7ce85f32ea833e8024f7bacd36d4e97 (diff)
downloadsrc-0b7939d725ba0ca903c5f8a3ca6d74347eb88690.tar.gz
src-0b7939d725ba0ca903c5f8a3ca6d74347eb88690.zip
fflush: correct buffer handling in __sflush
Two additional stdio changes followed 86a16ada1ea6 and need to be reverted as part of the fflush fix. This reverts commit 6e13794fbe6e82c21365d0fd66769bf8b19c0197. This reverts commit bafaa70b6f9098d83d074968c8e6747ecec1e118. Fixes: d09a3bf72c0b ("fflush: correct buffer handling in __sflush") Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D42491 (cherry picked from commit 4e0e01bf6511c28212d7dff94fe131a502e13026) (cherry picked from commit d2c65a1c948648f11342274029a3f18b90aa58d2) Approved by: so
-rw-r--r--lib/libc/stdio/fvwrite.c13
-rw-r--r--lib/libc/stdio/wbuf.c12
2 files changed, 4 insertions, 21 deletions
diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c
index dd170ee3d7dc..acf8f72076cf 100644
--- a/lib/libc/stdio/fvwrite.c
+++ b/lib/libc/stdio/fvwrite.c
@@ -52,7 +52,6 @@ int
__sfvwrite(FILE *fp, struct __suio *uio)
{
size_t len;
- unsigned char *old_p;
char *p;
struct __siov *iov;
int w, s;
@@ -136,12 +135,8 @@ __sfvwrite(FILE *fp, struct __suio *uio)
COPY(w);
/* fp->_w -= w; */ /* unneeded */
fp->_p += w;
- old_p = fp->_p;
- if (__fflush(fp) == EOF) {
- if (old_p == fp->_p)
- fp->_p -= w;
+ if (__fflush(fp))
goto err;
- }
} else if (len >= (w = fp->_bf._size)) {
/* write directly */
w = _swrite(fp, p, w);
@@ -180,12 +175,8 @@ __sfvwrite(FILE *fp, struct __suio *uio)
COPY(w);
/* fp->_w -= w; */
fp->_p += w;
- old_p = fp->_p;
- if (__fflush(fp) == EOF) {
- if (old_p == fp->_p)
- fp->_p -= w;
+ if (__fflush(fp))
goto err;
- }
} else if (s >= (w = fp->_bf._size)) {
w = _swrite(fp, p, w);
if (w <= 0)
diff --git a/lib/libc/stdio/wbuf.c b/lib/libc/stdio/wbuf.c
index 808cfa588cfb..558322b4001e 100644
--- a/lib/libc/stdio/wbuf.c
+++ b/lib/libc/stdio/wbuf.c
@@ -50,7 +50,6 @@ static char sccsid[] = "@(#)wbuf.c 8.1 (Berkeley) 6/4/93";
int
__swbuf(int c, FILE *fp)
{
- unsigned char *old_p;
int n;
/*
@@ -86,15 +85,8 @@ __swbuf(int c, FILE *fp)
}
fp->_w--;
*fp->_p++ = c;
- old_p = fp->_p;
- if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) {
- if (__fflush(fp) != 0) {
- if (fp->_p == old_p) {
- fp->_p--;
- fp->_w++;
- }
+ if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n'))
+ if (__fflush(fp) != 0)
return (EOF);
- }
- }
return (c);
}