From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AC922DB7AD for ; Sat, 31 Jan 2026 10:26:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769855183; cv=none; b=KTP474Ymz9noKk+TRumgRKFVG27hLNCZXV5Sei9Fu8HWwS4GKze21kT5n0EDSXbqy3GpMtI+38STVFBIBnggBkQ82HOwNFBzXgTFV1bJN6d9XQg5Rdzdj+aUv1bbRFdtzFUg0WZ63jKURHNPYHY7gNczO6gMwG7BBUsWxo0XiqI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769855183; c=relaxed/simple; bh=lkNLySDj3kdDXfxTVVea71OTCkJRWSmjduCCTIV1Gww=; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject: MIME-Version:Content-Type; b=De5gmWRfWRKPWvPKP/G2ljnVxUwV2CCcgKq1EiTK20DpvYPHDQ+ogDW1dxK0PkQfHS9K/SYUUp3sCuw1xPA41jsw8+76LjQtBOhQdqGV9HEQA8bwsbw1qF5tRRQzvTgGcfJuAluhjS26xaZvaTmAJisr4wtZSq9u3ZlRMMICJ5A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=GYM3rOJr; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="GYM3rOJr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1769854732; bh=lkNLySDj3kdDXfxTVVea71OTCkJRWSmjduCCTIV1Gww=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=GYM3rOJr0IUn3mzfgeQE9vWu5dQ9wWjEx+ah1DK07GqHqjrh45NO7njPW1cYcl4aY 03cbVNqHCI4+GHE2JGsgQfDXXfw6kTszNu3YxEfMzmwxEddlfy4gVblBan6/l9JMT9 gslDtbk9TeBdeS5Y9qduGIEc14LJuMQhqPGYSots= Date: Sat, 31 Jan 2026 11:18:49 +0100 From: =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= To: "licheng.li" Cc: Willy Tarreau , David Laight , linux-kernel@vger.kernel.org Message-ID: <222455c7-17a8-4b1f-a574-4e945467eb12@weissschuh.net> In-Reply-To: <20260130083737.1123-1-im.lechain@gmail.com> References: <20260130083737.1123-1-im.lechain@gmail.com> Subject: Re: [PATCH 1/2] tools/nolibc: add support zero pad (0) in printf 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 X-Correlation-ID: <222455c7-17a8-4b1f-a574-4e945467eb12@weissschuh.net> Hey Cheng, Jan 30, 2026 09:37:51 licheng.li : > From: Cheng Li > > This patch correctly implements the '0' flag in __nolibc_printf() to > allow zero-padding for numeric and pointer outputs. Thanks for (all of) your patches. I am not sure when exactly I can take a proper look at them. As we are currently fairly late in the 6.20/7.0 development cycle I would l= ike move your patches into the next one. We can still discuss the patches and you can send new revisions and patches= , but they won't be picked up until in a few weeks. > Thanks to David for pointing out the errors in the previous implementatio= n. > > The logic ensures that the sign ('-') for negative numbers or the prefix > ('0x') for pointers is printed before the padding zeros, adhering to > standard printf behavior (e.g., producing "-0005" instead of "000-5"). > > Examples of the corrected padding logic: > - ("%05d", -5)=C2=A0 -> "-0005" > - ("%05p", ptr)=C2=A0 -> "0x00..." > > Signed-off-by: Cheng Li > --- > tools/include/nolibc/stdio.h | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h > index f31b77f61d3b..8a4af259a31b 100644 > --- a/tools/include/nolibc/stdio.h > +++ b/tools/include/nolibc/stdio.h > @@ -267,7 +267,7 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t s= tate, size_t n, const char > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* we'= re in an escape sequence, ofs =3D=3D 1 */ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 escape= =3D 0; > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (c =3D= =3D '-') { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (c =3D= =3D '-' || c =3D=3D '0') { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 padc =3D c; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 c =3D fmt[ofs++]; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > @@ -364,9 +364,21 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t = state, size_t n, const char > =C2=A0=C2=A0=C2=A0=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