From nobody Mon Aug 28 23:38:31 2023 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 4RZRnz4HdWz4s55c; Mon, 28 Aug 2023 23:38:31 +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 4RZRnz3T4Zz4cfV; Mon, 28 Aug 2023 23:38:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693265911; 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=fzrBEcMVOt7Yia6KLpTI10Z5D2rxoHrqt/0/m+zSVJM=; b=QgWRxURKobk/Y6MGnmofZKkFkzJeDYB4XlHngnxBXgRRkf0d8Z0CasHCblbQSNF110ld+W 3PaaAidduBrrY6ZxU3o10aQ6w77R+6F8TlAYFZqSuYjdNKrZNi2q5h9oa5+Z5TepRBa/rb XOU7TxM1vh0Che5OmLlWlmNa/XioHC5CdOKIWaCm5mHQGNb3HYhpAml9emHG3O/md1EnKq AySngIme4kgQ4CVk2m+BLkV9zDOS7KuEyYKAYPqqi7EoJQPVT0AIXsDGBkfzULI5CAveJc Af94GdLEORKoqmAs981vSYbovArfzErZCVnT+XoY356kMg5dPa80v0zAzctTgA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1693265911; a=rsa-sha256; cv=none; b=yKxDZf+odFkn7nTWUGwWDo6PMEYB1aPEtIImIhIKTrSEf1xU5TWhKRZZZTwC8fK+WGMdaf C4skAx5jitYUbT60f2rZasAeKmOOmC6MO7H2IoFsEMYOPC+YdtXCdWepixSxJIUKiEgki9 et8arldfSYMREjOl+hTHigSfRZngPd67fuF2rnZ7EbeKj+g7IGNT4Pnv1V8b4gbT9jk2vE jUNPMXGWkNIiUIlm/n4eMWEquSC7AIOv+8Wd96esvLbOSLlLWAJe4y5LH1Hq34Vy5wZWsI BDCABaiQhSv+WvUa0jQXJIrGCgeEyFJbUfNyN/vEtlPW4VpU08rOOurCa7zgmQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693265911; 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=fzrBEcMVOt7Yia6KLpTI10Z5D2rxoHrqt/0/m+zSVJM=; b=SiDkasZ2gPOK2mG8dbdFDLlXSITRdnbF6MgWXT2JfCc+XLluPmMpGr7qyqU/yil5oVG8pR S2vtwd2JNOs9ptMurKHyhY7JNEqNNB+CyY4x1ojYMbkE970kyxbJc+WF4Kf2Mexf+e41XP zZdI6IIR+DUchJCK20i3c0puSpA1HUOQam9nr7Zxy4ad/EHLJuZ3OJRFILTjDAb/Wlj/sW TpUh35IzXgNNieK/gFJlA4h7RpCmJvYIeZJ2e5CbVrqfYDtoaMoPpA5O37t7T9ME+4mqlc bZDJOHfm3ZdlDWcbAhb6y15GJ0/9dv5V8vNpv7ZWqvdvMGKsMQLysK2w4e1lgQ== 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 4RZRnz2PzLzDHr; Mon, 28 Aug 2023 23:38:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37SNcVbR077813; Mon, 28 Aug 2023 23:38:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37SNcVx0077811; Mon, 28 Aug 2023 23:38:31 GMT (envelope-from git) Date: Mon, 28 Aug 2023 23:38:31 GMT Message-Id: <202308282338.37SNcVx0077811@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: aca3bd160257 - main - libc: Fix fixed-width case in the new integer parser. 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: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: aca3bd1602577591e5cd237c4bb0bb71b3be0c75 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=aca3bd1602577591e5cd237c4bb0bb71b3be0c75 commit aca3bd1602577591e5cd237c4bb0bb71b3be0c75 Author: Dag-Erling Smørgrav AuthorDate: 2023-08-28 23:38:09 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-08-28 23:38:19 +0000 libc: Fix fixed-width case in the new integer parser. Fixes: d9dc1603d6e4 Differential Revision: https://reviews.freebsd.org/D41622 --- lib/libc/stdio/vfscanf.c | 2 +- lib/libc/stdio/vfwscanf.c | 2 +- lib/libc/tests/stdio/sscanf_test.c | 17 +++++++++++++++++ lib/libc/tests/stdio/swscanf_test.c | 17 +++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c index b4db62c216ed..9727c9e70c34 100644 --- a/lib/libc/stdio/vfscanf.c +++ b/lib/libc/stdio/vfscanf.c @@ -452,7 +452,7 @@ parseint(FILE *fp, char * __restrict buf, int width, int base) } else if (state == haveprefix) { p--; (void) __ungetc(c, fp); - } else if (c != EOF) { + } else if (width && c != EOF) { (void) __ungetc(c, fp); } return (p - buf); diff --git a/lib/libc/stdio/vfwscanf.c b/lib/libc/stdio/vfwscanf.c index 3300751eafb6..b03c9dba0699 100644 --- a/lib/libc/stdio/vfwscanf.c +++ b/lib/libc/stdio/vfwscanf.c @@ -435,7 +435,7 @@ parseint(FILE *fp, wchar_t * __restrict buf, int width, int base, } else if (state == haveprefix) { wcp--; __ungetwc(c, fp, locale); - } else if (c != WEOF) { + } else if (width && c != WEOF) { __ungetwc(c, fp, locale); } return (wcp - buf); diff --git a/lib/libc/tests/stdio/sscanf_test.c b/lib/libc/tests/stdio/sscanf_test.c index 24226f3b3a8d..462b4a6586da 100644 --- a/lib/libc/tests/stdio/sscanf_test.c +++ b/lib/libc/tests/stdio/sscanf_test.c @@ -237,6 +237,22 @@ ATF_TC_BODY(sscanf_i, tc) } } +/* + * Test termination cases: non-numeric character, fixed width, EOF + */ +ATF_TC_WITHOUT_HEAD(sscanf_termination); +ATF_TC_BODY(sscanf_termination, tc) +{ + int a = 0, b = 0, c = 0; + char d = 0; + + ATF_CHECK_EQ(4, sscanf("3.1415", "%d%c%2d%d", &a, &d, &b, &c)); + ATF_CHECK_EQ(3, a); + ATF_CHECK_EQ(14, b); + ATF_CHECK_EQ(15, c); + ATF_CHECK_EQ('.', d); +} + ATF_TP_ADD_TCS(tp) { setlocale(LC_NUMERIC, "en_US.UTF-8"); @@ -245,5 +261,6 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, sscanf_d); ATF_TP_ADD_TC(tp, sscanf_x); ATF_TP_ADD_TC(tp, sscanf_i); + ATF_TP_ADD_TC(tp, sscanf_termination); return (atf_no_error()); } diff --git a/lib/libc/tests/stdio/swscanf_test.c b/lib/libc/tests/stdio/swscanf_test.c index 391a54e0ed5e..10eaf786e5fa 100644 --- a/lib/libc/tests/stdio/swscanf_test.c +++ b/lib/libc/tests/stdio/swscanf_test.c @@ -238,6 +238,22 @@ ATF_TC_BODY(swscanf_i, tc) } } +/* + * Test termination cases: non-numeric character, fixed width, EOF + */ +ATF_TC_WITHOUT_HEAD(swscanf_termination); +ATF_TC_BODY(swscanf_termination, tc) +{ + int a = 0, b = 0, c = 0; + char d = 0; + + ATF_CHECK_EQ(4, swscanf(L"3.1415", L"%d%c%2d%d", &a, &d, &b, &c)); + ATF_CHECK_EQ(3, a); + ATF_CHECK_EQ(14, b); + ATF_CHECK_EQ(15, c); + ATF_CHECK_EQ(L'.', d); +} + ATF_TP_ADD_TCS(tp) { setlocale(LC_NUMERIC, "en_US.UTF-8"); @@ -246,5 +262,6 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, swscanf_d); ATF_TP_ADD_TC(tp, swscanf_x); ATF_TP_ADD_TC(tp, swscanf_i); + ATF_TP_ADD_TC(tp, swscanf_termination); return (atf_no_error()); }