From nobody Fri Sep 6 18:35:09 2024 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 4X0lJs6y9Rz5VRmP; Fri, 06 Sep 2024 18:35:09 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X0lJs6TJ5z4VNp; Fri, 6 Sep 2024 18:35:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725647709; 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=Gjrs7eVHjCS3uj1Dtj7JSB/gZPLMwA3K1TShi/Cg7JA=; b=WTIDHy2txV5ZCP+h9g+PGTrXLxkVOBRuWTIPW/8PG3o9TurjgCLDmcdlwW8w3RRwzgpEnd NeNqdFuIWHSOTORij/EMlrOUWiuSo2RnMKTbUo5DSs27KNH8HHnYWzzUHsasfEqSG5win7 t8mkJ8hiyMeTf87mSdYsUC/ygdiikdEt4AowIiE1HmX/6jcKoeySexjdNqX7owt5DnHzTj lZe8lSIo5j4THTGG+nu0+cfDbjINVOYh/yRfJy4AEmL0vswGya4+Uibb54b4RwEVNQBTMV ZyEXXV6kZBSl4hZtx3Gr03VORh13r1Eh25ApWDrAzwMl6frs30j3kLGdR8Zehg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725647709; a=rsa-sha256; cv=none; b=S+p9475X3VVMCDIK4aArD05asIM+pr93SLLJXJEAm2/jim9rix8Rkx8TctiVOVNMWFbWR7 y9BaMUc13HkZ4zf96Wx3qi6bVFfD/brwoAl9Wn6ckajQNwXgNHakI1E2ULYEp2bcR+7lX5 j8L+5ezGgx8fRx1j1veta1I2MwGtp9MA+nu7mqtikCzxmL92PPggrbjzm85icJwVL0HngE ur2XUizKClO6RPP8VWPFKpM7cnjiGuSdcSikzlF7P5DJwHIz2/FXOm5ILp2/Lpc8lz6vhM 0rjPlNaVk6Uyl3OLBnEzEfmTB7yWkkbC/F6n7ALg8xAbpFdrEgl6AiLUcYKPGg== 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=1725647709; 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=Gjrs7eVHjCS3uj1Dtj7JSB/gZPLMwA3K1TShi/Cg7JA=; b=fQGE1OFYBbOFaI0lkHmUW4r5b8KTcXpQxfll+IE4nSkdChiaOl4jFIBTyFov6LAi3pu0/r ZxnvlervTz/oipZnF7o2l2ZasOuh0lgMSoaD7Zhx9+bR7dLbv4TqJkBltWGbU1D4ONSlcH E/5jLHiAaJxzn09qJPNOqGIGCSw8RnPt2Sgw8gg6CKQ99jMsOUxJGs7OUCCNM9Y0dRLyKB 6xoZS06r7LP2ZCtPQzMo/TCpWGFv4LrXryiL3eojbf7S2hZlGbiH/8Ku8Mhqjzf8aUotu4 2RtzzQQmupkyn4Gv/t1WCvLstRunAl/wmByBVzMUmXmfS0OazzkggtfZHKrgiw== 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 4X0lJs62nTz137t; Fri, 6 Sep 2024 18:35:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 486IZ9m4010544; Fri, 6 Sep 2024 18:35:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 486IZ9Fd010541; Fri, 6 Sep 2024 18:35:09 GMT (envelope-from git) Date: Fri, 6 Sep 2024 18:35:09 GMT Message-Id: <202409061835.486IZ9Fd010541@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 07d90ee0a621 - main - kvprintf(): Fix '+' conversion handling 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 07d90ee0a62110e5161bb0b8a3a0b1b9d2beabad Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=07d90ee0a62110e5161bb0b8a3a0b1b9d2beabad commit 07d90ee0a62110e5161bb0b8a3a0b1b9d2beabad Author: Sebastian Huber AuthorDate: 2024-06-14 07:30:28 +0000 Commit: Warner Losh CommitDate: 2024-09-06 18:34:30 +0000 kvprintf(): Fix '+' conversion handling For example, printf("%+i", 1) prints "+1". However, kvprintf() did print just "1" for this example. According to PRINTF(3): A sign must always be placed before a number produced by a signed conversion. For "%+r" radix conversions, keep the "+" handling as it is, since this is a non-standard conversion. For "%+p" pointer conversions, continue to ignore the sign modifier to be in line with libc. This change allows to support the ' conversion modifier in the future. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1310 --- sys/kern/subr_prf.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 4dc989e2d1f1..8ecabdec18d5 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -660,9 +660,9 @@ kvprintf(char const *fmt, void (*func)(int, void*), void *arg, int radix, va_lis char *d; const char *p, *percent, *q; u_char *up; - int ch, n; + int ch, n, sign; uintmax_t num; - int base, lflag, qflag, tmp, width, ladjust, sharpflag, neg, sign, dot; + int base, lflag, qflag, tmp, width, ladjust, sharpflag, dot; int cflag, hflag, jflag, tflag, zflag; int bconv, dwidth, upper; char padc; @@ -690,7 +690,7 @@ kvprintf(char const *fmt, void (*func)(int, void*), void *arg, int radix, va_lis PCHAR(ch); } percent = fmt - 1; - qflag = 0; lflag = 0; ladjust = 0; sharpflag = 0; neg = 0; + qflag = 0; lflag = 0; ladjust = 0; sharpflag = 0; sign = 0; dot = 0; bconv = 0; dwidth = 0; upper = 0; cflag = 0; hflag = 0; jflag = 0; tflag = 0; zflag = 0; reswitch: switch (ch = (u_char)*fmt++) { @@ -701,7 +701,7 @@ reswitch: switch (ch = (u_char)*fmt++) { sharpflag = 1; goto reswitch; case '+': - sign = 1; + sign = '+'; goto reswitch; case '-': ladjust = 1; @@ -771,7 +771,6 @@ reswitch: switch (ch = (u_char)*fmt++) { case 'd': case 'i': base = 10; - sign = 1; goto handle_sign; case 'h': if (hflag) { @@ -824,8 +823,10 @@ reswitch: switch (ch = (u_char)*fmt++) { goto reswitch; case 'r': base = radix; - if (sign) + if (sign) { + sign = 0; goto handle_sign; + } goto handle_nosign; case 's': p = va_arg(ap, char *); @@ -862,13 +863,11 @@ reswitch: switch (ch = (u_char)*fmt++) { goto handle_nosign; case 'y': base = 16; - sign = 1; goto handle_sign; case 'z': zflag = 1; goto reswitch; handle_nosign: - sign = 0; if (jflag) num = va_arg(ap, uintmax_t); else if (qflag) @@ -907,11 +906,11 @@ handle_sign: num = (signed char)va_arg(ap, int); else num = va_arg(ap, int); -number: - if (sign && (intmax_t)num < 0) { - neg = 1; + if ((intmax_t)num < 0) { + sign = '-'; num = -(intmax_t)num; } +number: p = ksprintn(nbuf, num, base, &n, upper); tmp = 0; if (sharpflag && num != 0) { @@ -920,7 +919,7 @@ number: else if (base == 16) tmp += 2; } - if (neg) + if (sign) tmp++; if (!ladjust && padc == '0') @@ -930,8 +929,8 @@ number: if (!ladjust) while (width-- > 0) PCHAR(' '); - if (neg) - PCHAR('-'); + if (sign) + PCHAR(sign); if (sharpflag && num != 0) { if (base == 8) { PCHAR('0');