From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4EEA30EF84 for ; Wed, 25 Mar 2026 23:03:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774479834; cv=none; b=VCeKARY5d4thSmtiID9aofq7p4qse+ctuGdWI6hDz62WcNbUM3VEJvRUS+3Vk/QztE3MOA+ROQQ0q3ksjd0YxTdUhVLYv2DH3vOMN2L35PgRUFUV29R/t54VYcpmXrVdpsF4p/id0xsA2wVZcO3whBQAvc2dKUE/vnSujJbEWZ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774479834; c=relaxed/simple; bh=62k9GDXE6GiT9tcrZ1Lm8etbto0wmLwXAUhotQ/e7hY=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EbKLY167xne+PfXYtIAEyCbh3f5qvbDXIQ+WPoldeQbGL5/CpatnstYT0hgNrFns0XVybAe0QHtGtTur8ODMFH3NOxXIe3WjySv6+TmnqatEETidNe+chGwvrSut/MkGVGojPK2fSS1q6Audu7MBIXX48u8yRLR60gEO4hf5l6c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Rg8owh0B; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Rg8owh0B" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-43b949bf4easo74258f8f.0 for ; Wed, 25 Mar 2026 16:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774479831; x=1775084631; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=SeHfclJ5oIPg9OgphQJmG+5hWT5Hcyt5b7FD7iRX7E0=; b=Rg8owh0B4++z3KVNnGgXaHXYi8dEPaT3RV3+G6qwwhSCMtc1QsMbcL41YMRVr1IaPt iiWcD5EQJol4xy2yRyJJeyrxWliULfBflLZzqbA0cgl3DQnDZHLruJvKbHRxCep84b6b e76HmZjYZtT+WsveXLhHMXBOobHazJu/MS9G5cG2rONvvWtSP2VpqcUDE7ZlOpqynGht ju1usq8q4d8+3WkK32Lk3LipqKBLwGYkQS/3yeZKtFKLxRjsTpYynjhntObPK/s6KXhM anqWoBIZAcSszxv5fdl6kuMgPq5Lrt4t08p8yQYmwTfZchZ6/0hY3R2p19GOO3t1tU1Q aIvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774479831; x=1775084631; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=SeHfclJ5oIPg9OgphQJmG+5hWT5Hcyt5b7FD7iRX7E0=; b=Kpx0XrnevkoLtjKcVpkEqnYTRDYuq3FqRZcFvDL1w5mBQaB9d2nL8OLp7HwS/xfJ+P 1ZoOviaPXpyH7HVp7yssKxX4CCxhKhBAOQRw08XtPrE1OK3qJpxH74OJgAqUL7w0FEqy v3cSYdoMtlWEwI0jbv1glVbQGolGe1ng68CdIOEnDmq+YWx9UjnzIACkCa9sYPCICYII qqcQgpoH08nt0P0n6vtsFMycMsIcRV2gydm3ZKxDNHUWeWDbHGt2aGG6yCwfODU5Ne1f 1mUHVgySctXkZaL1kVIguE1etN2e2BsnIPPiwFn4Wi1hRQ6mCjWqhwycJHvgxodUGBJe swqw== X-Forwarded-Encrypted: i=1; AJvYcCVI7JBXeRJGSfjl6QhxdL2c/VgeMNzhoSG0B24sgtW7nAtRBgK7V4v9HswcRfyz9XE3IjWNXVjPiauC+XI=@vger.kernel.org X-Gm-Message-State: AOJu0YxZ8Db+9B776xf0Y+LLYhLlv3zeE0tefG70xrkCAN4/S/3iBQbU 6W2GSmCYzPj3rrKj4x/5LX/suqgB+qD+NM5T3lcaOb9Djo9+900EsyHIXBETFXFM X-Gm-Gg: ATEYQzyy3f4thpDtruir+K5iZualbJ8foAyW9fIcRp/DiY+gTS1Y7qjYwHBrFDXJUsN 5JRGM4mxAF0yS6E9nOsAF88I83qUGSImo3AnGWN1kjOvOWKwktitPDPYi6gm4kr1C2jLcvGLPuL fw7YRYmkiNA4p0wbpzTvyea+xK/BMti0+UsLesg8U8m5Y3xbYxrPkNSHQogHtyQMxfzUIOunsoE oJJeEyfAkaA//JxFahn9VaiuzWOcpHm29Qum0Xc4zg579OlCGVPZ8AKXZ7EjWKZfC7Y5Ivn1jFX IhVK1pbKIvVyONoXDqBLJAL2Re66xbE2VtHS7M0jfdPzxGe2x3+1LeIp2wqn9suDwKAGLZQqIxW Du+qmDQAargtNvTc+Ajd1ji4elcQBQL5+HYGMjDCs81brvv+F8TUzjMBkJ4dcA/osQabKBGej1h CSZgB43bTqlzct3zLtr5ticPyEedx+er843iZOGTzAU6e7rnhNBZvj5p40tWOMQ1Oc X-Received: by 2002:a05:600c:1e88:b0:47e:e59c:67c5 with SMTP id 5b1f17b1804b1-4871603a058mr71901875e9.8.1774479830516; Wed, 25 Mar 2026 16:03:50 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48720901ac9sm1746775e9.14.2026.03.25.16.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2026 16:03:48 -0700 (PDT) Date: Wed, 25 Mar 2026 23:03:47 +0000 From: David Laight To: Thomas =?UTF-8?B?V2Vpw59zY2h1aA==?= Cc: Willy Tarreau , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] tools/nolibc/printf: Support negative variable width and precision Message-ID: <20260325230347.5663ad33@pumpkin> In-Reply-To: References: <20260323112247.3196-1-david.laight.linux@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, 25 Mar 2026 21:37:11 +0100 Thomas Wei=C3=9Fschuh wrote: > Hi David, >=20 > thanks again for your patch! >=20 > On 2026-03-23 11:22:47+0000, david.laight.linux@gmail.com wrote: > > From: David Laight > >=20 > > For (eg) "%*.*s" treat a negative field width as a request to left align > > the output (the same as the '-' flag), and a negative precision to > > request the default precision. =20 >=20 > This makes sense, so far so good. >=20 > > Set the default precision to -1 (not INT_MAX) and add explicit checks > > to the string handling for negative values (makes the tet unsigned). =20 >=20 > 'tet'? test - I wanted to say that the test: len =3D precision < 0 || precision >=3D 6 ? 6 : 0; isn't actually a double comparison. Perhaps it isn't needed. >=20 > > For numeric output check for 'precision >=3D 0' instead of testing > > _NOLIBC_PF_FLAGS_CONTAIN(flags, '.'). > > This needs an inverted test, some extra goto and removes an indentation. > > The changed conditionals fix printf("%0-#o", 0) - but '0' and '-' shoul= dn't > > both be specified. =20 >=20 > Is this also related to the negative field width as described above? > If yes, could you explain how? If not, please split it out. > In general, the smaller the patches, the easier the review. Everything except the 'if (width < 0)' test is one change. It also changes v5 15/17, I did it as a delta (rather than a replacement patch) because of the later changes. The fix for printf("%0-#o", 0) (without these changes it generates "00") happens because of the way the conditionals and gotos change. Patch v5 15/17 that added zero padding and field precision had two 'goto prepend_sign', patch 16 (add octal) needs them to go opposite sides of the 'if (sign_prefix =3D=3D *out)' test. With the changed conditionals you need both labels or ("%#o", 0) always goes wrong. >=20 > > Best viewed with 'git diff -b' after being commited. =20 >=20 > This should go after '---'. No reason on its own to resend, though. >=20 > > Additional test cases added. =20 >=20 > No need to mention that, it is obvious from the diff :-) >=20 > > Signed-off-by: David Laight > > --- > >=20 > > I missed this bit in the earlier patches. > > Size wise it is pretty neutral. It really seems to depend on how many r= egisters > > get saved across the call to _nolibc_u64toa_base() - gcc doesn't seem t= o use > > the correct registers to avoid spills. > >=20 > > I did look at whether making 'width' negative at the top was better than > > keeping a '-' flag - but it bloats things because you need the absolute= value > > at the bottom. > >=20 > > tools/include/nolibc/stdio.h | 68 +++++++++++--------- > > tools/testing/selftests/nolibc/nolibc-test.c | 5 +- > > 2 files changed, 41 insertions(+), 32 deletions(-) > >=20 > > diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h > > index 8f7e1948a651..b6d14a58cfe7 100644 > > --- a/tools/include/nolibc/stdio.h > > +++ b/tools/include/nolibc/stdio.h > > @@ -347,6 +347,7 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *st= ate, const char *fmt, va_list > > char *out; > > const char *outstr; > > unsigned int sign_prefix; > > + int got_width; =20 >=20 > bool? There weren't any others in this file and I'm 'old school'... David >=20 > (...) >=20 > Otherwise looks good from what I understand. > But smaller patches would really give me more confidence. >=20 >=20 > Thomas