From nobody Tue Nov 01 00:46:32 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 4N1WYP0hvpz4gy16; Tue, 1 Nov 2022 00:46:33 +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 4N1WYP03Vhz3RDQ; Tue, 1 Nov 2022 00:46:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667263593; 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=LQIDv5ij/eCElngyg+MBW8QdeTpDSWU7yDRS/B8dv3o=; b=VXblNjRMUl6oxw3nTq2UyXmNbQGcRoQUkjBKz9F45VRWAq7y1RmrTNOJDJdKfBrTGzHTiG yOExGHK0fHyKzphD9MIpTqjhufTmjiGhk076RzLpn28QRu/RsOn69mSzKuoXLv6bPrFlmV 12ku63/zIX1LNOUrmFAv9NIhMs3xoxPyM2824soKKYQoJhAwHhkm6GbUxDr6xdXtQuHd/N wblm+Ga+6dM0IMxFsWloS1DqwKMUYn4H3pdVpsfxRFSCtlDODk6tJLAyam7MQNZjEpNOxq Y/9qubOEERZbllxs1FTWWeJpa0Z/6DlibfsGn0XcI5pyfqurlgSVSNPVuZmjYA== 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 4N1WYN6H34zwmc; Tue, 1 Nov 2022 00:46:32 +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 2A10kW5C042058; Tue, 1 Nov 2022 00:46:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2A10kWlp042057; Tue, 1 Nov 2022 00:46:32 GMT (envelope-from git) Date: Tue, 1 Nov 2022 00:46:32 GMT Message-Id: <202211010046.2A10kWlp042057@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 8e5a2135210d - stable/13 - strfmon: Fix alignment when enclosed by parentheses 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 8e5a2135210d2c53ef8bdcbb1b268d4bb5081f04 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667263593; 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=LQIDv5ij/eCElngyg+MBW8QdeTpDSWU7yDRS/B8dv3o=; b=ZMM2dRf7G+ijn5hIT3HIYOoCTu0jWrPdRExU528M/gr0YnrCsuDpRL9GSSsohsDzVcp/jO DM8Qh5EJuNUDFSKs103U3h8bz45m0Q7A8Ktg3s+D0vnnaumSomGzi/qvyMaiSyZoTWIxmt csiLZBYjG/6C3Nyt5+C9Rovybc8WLZu9eV7eaaSk0DIgvqer+E0C96SvnxgZ8lHRN8874h 1i7FT0W1a3imV+I8kSs6FN7gf6jBZMMai76kOUJPwjv+eW0Ge+VNi97W6QY28jwcV9/OYs ZoPXWsGENx8KS/WiXFe/44iVYL3qxwr6r+vm8bSsZUXZumNW6rS+dZP56pamvQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667263593; a=rsa-sha256; cv=none; b=M+AxPmeZcVbT4ESOP+oDUIy9ZbSGCtaWqovL0PJ5cP3gLvbPT1iqMLpvV2JTUEt3r7FRge pcm9Cf8i5eirlw0JWUSW7MYk2GH2lLWBU+ECW5JkpjdO34bWJe49+90WzYDNIlr3m7Wv6s tCgBg4Kok2BjIAJv4qxc+EG5BpTiSlG1rFfIb0U/OOaIEJhZwDjfeBXfltNCorKt+Oavly OWFtHXnPs/V9GNQPDgXVTMX61rrr9et8Yn+e9k2J1gM1tFh48s/15oSB6yXVE2xJuSW/YK ekg/LOOwu38cnmV9XlB+vaxxdWShjPCQLv8DahRhCARG8XxSCEaO0/ozEp7z/g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=8e5a2135210d2c53ef8bdcbb1b268d4bb5081f04 commit 8e5a2135210d2c53ef8bdcbb1b268d4bb5081f04 Author: Jose Luis Duran AuthorDate: 2022-10-14 23:26:32 +0000 Commit: Konstantin Belousov CommitDate: 2022-11-01 00:44:41 +0000 strfmon: Fix alignment when enclosed by parentheses (cherry picked from commit 947efadc3d6e778a824618d82f53f061bec69b77) --- lib/libc/stdlib/strfmon.c | 12 ++++++++++-- lib/libc/tests/stdlib/strfmon_test.c | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/libc/stdlib/strfmon.c b/lib/libc/stdlib/strfmon.c index d6619f4d7d54..a26521bb694d 100644 --- a/lib/libc/stdlib/strfmon.c +++ b/lib/libc/stdlib/strfmon.c @@ -373,8 +373,12 @@ vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, PRINTS(signstr); } - if (sign_posn == 0 && (flags & IS_NEGATIVE)) - PRINT(')'); + if (sign_posn == 0) { + if (flags & IS_NEGATIVE) + PRINT(')'); + else if (left_prec >= 0) + PRINT(' '); + } if (dst - tmpptr < width) { if (flags & LEFT_JUSTIFY) { @@ -466,6 +470,10 @@ __calc_left_pad(int flags, char *cur_symb) } switch (sign_posn) { + case 0: + if (flags & IS_NEGATIVE) + left_chars++; + break; case 1: left_chars += strlen(signstr); break; diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c index b5b22f9a483d..d4d1f6a580d9 100644 --- a/lib/libc/tests/stdlib/strfmon_test.c +++ b/lib/libc/tests/stdlib/strfmon_test.c @@ -81,8 +81,8 @@ ATF_TC_BODY(strfmon_examples, tc) { "%^#5n", "[ $ 123.45] [-$ 123.45] [ $ 3456.78]" }, { "%^#5.0n", "[ $ 123] [-$ 123] [ $ 3457]" }, { "%^#5.4n", "[ $ 123.4500] [-$ 123.4500] [ $ 3456.7810]" }, - { "%(#5n", "[$ 123.45] [($ 123.45)] [$ 3,456.78]" }, /* XXX */ - { "%!(#5n", "[ 123.45] [( 123.45)] [ 3,456.78]" }, /* XXX */ + { "%(#5n", "[ $ 123.45 ] [($ 123.45)] [ $ 3,456.78 ]" }, + { "%!(#5n", "[ 123.45 ] [( 123.45)] [ 3,456.78 ]" }, { "%-14#5.4n", "[ $ 123.4500 ] [-$ 123.4500 ] [ $ 3,456.7810 ]" }, { "%14#5.4n", "[ $ 123.4500] [ -$ 123.4500] [ $ 3,456.7810]" }, };