From nobody Tue Jan 25 15:26:10 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 5BD4B198089B; Tue, 25 Jan 2022 15:26:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JjrKZ1jktz3Jny; Tue, 25 Jan 2022 15:26:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643124370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QSLKscsKAtU1zE/04e95cQig359ec5EPedN7y77H5SE=; b=pAoyvjj2xFb52Xb5qicKWbRq3Y3tYaHGIGN2CAw2x2Nsc0SwP85+VXp4cRxtGBNt4TLb5P I116s9+r0hJnuEeUAL6VnmFmGfsIVSqZxLxlX7DbhOzfwdNQEeqx4u1E9cmNk7BJs9ooQb YimyOfpO6IkZWrJFmIPrwcws/xyysyjKmPAK27i2tcYpa5ywPzqr1s7qWkwxDrbfQg4BBQ OQOdi2v/e8VysrJpTPTz8BeL1YEoh+Wzi0Og8UKxnfYdWIruUUhV/KF48qS54oCq3PAySk vJNpnjXFxkcXM4l2ucTa47k68OsnIkEKEc9xvAe7g+thtQfXv4TwTb/Zk3JFJg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1BFE1442D; Tue, 25 Jan 2022 15:26:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20PFQA9J054129; Tue, 25 Jan 2022 15:26:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20PFQAwL054128; Tue, 25 Jan 2022 15:26:10 GMT (envelope-from git) Date: Tue, 25 Jan 2022 15:26:10 GMT Message-Id: <202201251526.20PFQAwL054128@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 86a16ada1ea6 - main - __sflush(): on write error, if nothing was written, reset FILE state back List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 86a16ada1ea608408cec370171d9f59353e97c77 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643124370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QSLKscsKAtU1zE/04e95cQig359ec5EPedN7y77H5SE=; b=RxSnLEgwGDe6aq7opAZsxrNQXjNeLXftGBWoCTVQ2tXgduDjCMV4KuxNRBUY7p+kNv+lnN R/eL/RZju4vgM7jdvPRVa/kJWNL0CNWbkD0nYdJaeGHbN8pvi4ZSn6RiomKNkOJnZvkEFW h2xFig1eLS1YSAHoCA+AZoeJYat4CxZO1bugPEWQ7wN2TdCP8e9Yf/I09blDk9cbxptq3I 1XELhE7mceovL7Fnh3S4w6Zvkq2Sbow3xWgbykoga3wj473Br0UeUsHPoEkFhjXbXB0mDQ snvqpjXhPm/W6hgMdpjhkPdJs2Yr6O8nLzqawE+QLIuO1CJAcGeofHe8VjBjZg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643124370; a=rsa-sha256; cv=none; b=Yui5przieVcegR5bapCfT/vftbhd2zRv5qw5hhMUfOQbaXqefVT9CrUfXt8E4KlnEZoFC1 rjpn1kemGer5/fFJodYWaAlXjF9Vc+bFxaFFb4NS/r8Kleo3iuYQeX9sPo5KHjnmy1TmfD G4GPdPzWScUXcXvyROkDM/E6+6LMsv+lGVjGBYJaXAhy9w/1kLpeNxRxYAu3tV1SO1Vmy0 op0OPhOFgIj2tJ5yqq8Wmqx9ADZuzr1nMBv+ercjMQdD7IS2/Q8N/Mh+gO/ZLdMIx6JTkR BcFxByqd51LZwQKSpve/+xS2YsU5P4vvUm3/gOrl5iRuk2gYmxx63DQYbsn+ZQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=86a16ada1ea608408cec370171d9f59353e97c77 commit 86a16ada1ea608408cec370171d9f59353e97c77 Author: Konstantin Belousov AuthorDate: 2022-01-23 06:52:59 +0000 Commit: Konstantin Belousov CommitDate: 2022-01-25 15:26:05 +0000 __sflush(): on write error, if nothing was written, reset FILE state back otherwise the data is just dropped. Check for current position equal to the buffer base at the entry of the function; if not equal, setvbuf() was done from the write method and it is not our business to override the decision. PR: 76398 Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D34007 --- lib/libc/stdio/fflush.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c index f7d2fbdc28e5..decc974907f4 100644 --- a/lib/libc/stdio/fflush.c +++ b/lib/libc/stdio/fflush.c @@ -105,8 +105,8 @@ __weak_reference(__fflush, fflush_unlocked); int __sflush(FILE *fp) { - unsigned char *p; - int n, t; + unsigned char *p, *old_p; + int n, t, old_w; t = fp->_flags; if ((t & __SWR) == 0) @@ -121,7 +121,9 @@ __sflush(FILE *fp) * Set these immediately to avoid problems with longjmp and to allow * exchange buffering (via setvbuf) in user write function. */ + old_p = fp->_p; fp->_p = p; + old_w = fp->_w; fp->_w = t & (__SLBF|__SNBF) ? 0 : fp->_bf._size; for (; n > 0; n -= t, p += t) { @@ -134,6 +136,9 @@ __sflush(FILE *fp) fp->_p += n; if ((fp->_flags & (__SLBF | __SNBF)) == 0) fp->_w -= n; + } else if (p == fp->_p) { /* cond. to handle setvbuf */ + fp->_p = old_p; + fp->_w = old_w; } fp->_flags |= __SERR; return (EOF);