From nobody Thu Mar 31 15:57:02 2022 X-Original-To: dev-commits-src-all@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 042FF1A3AEBE; Thu, 31 Mar 2022 15:57:03 +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 4KTnxB6Zk8z4Wt9; Thu, 31 Mar 2022 15:57:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648742222; 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=Tkedx67+9GaSEv9IvtjOS4Yd0qc98B7vrcfM1E5w0oE=; b=qVo/YjGKFK2EWfsigbHKshu7+vBo7g1/Xl6dR+hzWQhdbPgg/JV48a9mTFAeqnElb6GBHc QwhcMzuCL/SN66PAUqlo3Mk7AuSfq3jSZliQfnYg6V4RC1LOhkRY0BwxW+WAMQ9uOi+cnl 22yEfPXehjZZupqw7036IuqQx/lM+xdmC2jURNHTSpk8ASC1RflepgLwiGzjqjHP59Peim MFrh36BJocUPC6QLJvzKBPJom10Xv4YDvmL6JsXZq9ICZbM74pjd0gSQRRe/bF+FbubtQb LdaMOttbyoz2+7xcWEqmGRJkHs9IMnV7LxO7K+IAYv3qc3vbzuXAX02NJ+3wNw== 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 C1B592A1C3; Thu, 31 Mar 2022 15:57:02 +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 22VFv2tH080954; Thu, 31 Mar 2022 15:57:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22VFv22Y080953; Thu, 31 Mar 2022 15:57:02 GMT (envelope-from git) Date: Thu, 31 Mar 2022 15:57:02 GMT Message-Id: <202203311557.22VFv22Y080953@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 3ca78fba9653 - releng/13.1 - libc: Restore fp state upon flush error in fputc List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.1 X-Git-Reftype: branch X-Git-Commit: 3ca78fba965377cce04935ee762f1d91e54efeb1 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648742222; 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=Tkedx67+9GaSEv9IvtjOS4Yd0qc98B7vrcfM1E5w0oE=; b=swADV3wseTZXHwoPENeNObsiuOismpmpdA8GHPgKKh+6a3wMEH5Bg5GbOZQDcF+EqK7yfR 0aXvbs/S/WfDKrUMB2OTGubzB4GU4GJ/eCSpo+4k7lmOaNuMssE/R4l8aFjn2yipKg3bNb qHOLIvvB0rt8TvmylNWiVwEHPnR+0vVCBhr6d95LFNCexUOytGMz/sfNVJG7yxG890tE+O K/X4cZFv29ygVLZifZLJujJv0hf4JSin2dsKtGllImDPgyaAQyelQywqlF62PURvFtW4j2 THcHKy268gKFe1SQtGmnm8PgXIkLGf91NG4MDLndiyrY3Yx4IHeWIlcLtTI4Hg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648742222; a=rsa-sha256; cv=none; b=rQQgeCGBKAUBiQpMXayzycf2fxNIHn3ZAQ+nagGGhhxlqvQWkr2YPlw6YtW2TDM3yzcVxJ g84vK9etcnBuubRB95b9yHy9z6fGfHX78pTmSEsdZQmzIQDKwD2Z5EUM+qzi0eoaz2yPgU UWE/jCD7PmDPuGusJB/BrY9iMrdefFRIR5ic+sl99flG28tWZ7AuxuQ6mBXCsd2M77gNuh gmvO4RVB04WBBW0AggOuGzs9iy8/Kx7NxzH1iQ7Z5icU4AVc6BA8goSlTybYuwdttTiktg msOI60Kn4KBmFrwBc+1n0W6KNGqJTK8IKa5ktTgWWIiy+NjnSDgkFWSLGXb1mg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=3ca78fba965377cce04935ee762f1d91e54efeb1 commit 3ca78fba965377cce04935ee762f1d91e54efeb1 Author: Mark Johnston AuthorDate: 2022-03-25 14:46:24 +0000 Commit: Mark Johnston CommitDate: 2022-03-31 15:56:37 +0000 libc: Restore fp state upon flush error in fputc This is akin to commit bafaa70b6f9098d83d074968c8e6747ecec1e118. Approved by: re (gjb) Reported by: Guy Yur Fixes: 86a16ada1ea6 Sponsored by: The FreeBSD Foundation (cherry picked from commit 6e13794fbe6e82c21365d0fd66769bf8b19c0197) (cherry picked from commit 7be0c792c46c5a1faf46b611058953aa85b192d6) --- lib/libc/stdio/wbuf.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/libc/stdio/wbuf.c b/lib/libc/stdio/wbuf.c index e1aa70243e94..6cd75145a271 100644 --- a/lib/libc/stdio/wbuf.c +++ b/lib/libc/stdio/wbuf.c @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); int __swbuf(int c, FILE *fp) { + unsigned char *old_p; int n; /* @@ -87,8 +88,15 @@ __swbuf(int c, FILE *fp) } fp->_w--; *fp->_p++ = c; - if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) - if (__fflush(fp)) + old_p = fp->_p; + if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) { + if (__fflush(fp)) { + if (fp->_p == old_p) { + fp->_p--; + fp->_w++; + } return (EOF); + } + } return (c); }