All of lore.kernel.org
 help / color / mirror / Atom feed
From: "licheng.li" <im.lechain@gmail.com>
To: Willy Tarreau <w@1wt.eu>, David Laight <david.laight.linux@gmail.com>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
	linux-kernel@vger.kernel.org, im.lechain@gmail.com
Subject: [PATCH 2/2] selftests/nolibc: add tests for printf zero padding (0)
Date: Fri, 30 Jan 2026 16:37:36 +0800	[thread overview]
Message-ID: <20260130083737.1123-2-im.lechain@gmail.com> (raw)
In-Reply-To: <20260130083737.1123-1-im.lechain@gmail.com>

From: Cheng Li <im.lechain@gmail.com>

This patch adds validation for the '0' flag in printf() to ensure correct
behavior for pointers, positive integers, and negative integers.

The tests specifically verify that:
 - Pointers include the '0x' prefix before padding.
 - Negative numbers include the '-' sign before padding.
 - Width and padding are correctly calculated.

Signed-off-by: Cheng Li <im.lechain@gmail.com>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index c11fcf6c5075..77bb8796aa3d 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1723,6 +1723,9 @@ static int run_printf(int min, int max)
 		CASE_TEST(truncation);   EXPECT_VFPRINTF(25, "01234567890123456789", "%s", "0123456789012345678901234"); break;
 		CASE_TEST(string_width); EXPECT_VFPRINTF(10, "         1", "%10s", "1"); break;
 		CASE_TEST(number_width); EXPECT_VFPRINTF(10, "         1", "%10d", 1); break;
+		CASE_TEST(zero_pad_ptr); EXPECT_VFPRINTF(5, "0x005", "%05p", (void *)5); break;
+		CASE_TEST(zero_pad_int); EXPECT_VFPRINTF(5, "00005", "%05d", 5); break;
+		CASE_TEST(zero_pad_neg); EXPECT_VFPRINTF(5, "-0005", "%05d", -5); break;
 		CASE_TEST(number_left);  EXPECT_VFPRINTF(10, "|-5      |", "|%-8d|", -5); break;
 		CASE_TEST(string_align); EXPECT_VFPRINTF(10, "|foo     |", "|%-8s|", "foo"); break;
 		CASE_TEST(width_trunc);  EXPECT_VFPRINTF(25, "                    ", "%25d", 1); break;
-- 
2.52.0


  reply	other threads:[~2026-01-30  8:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-30  8:37 [PATCH 1/2] tools/nolibc: add support zero pad (0) in printf licheng.li
2026-01-30  8:37 ` licheng.li [this message]
2026-01-30 10:02 ` David Laight
2026-01-30 10:12   ` Cheng Li
2026-01-30 14:58     ` David Laight
2026-01-31  3:44       ` Cheng Li
2026-01-31 10:18 ` Thomas Weißschuh
2026-01-31 12:32   ` David Laight
2026-02-01  0:49     ` Cheng Li
2026-02-01  8:56       ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260130083737.1123-2-im.lechain@gmail.com \
    --to=im.lechain@gmail.com \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.