From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (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 36F8839A81C for ; Mon, 2 Mar 2026 10:18:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772446735; cv=none; b=G5fcusa4peGxNdOI73aF0IPdoammXlu+kVTZZnu6bJa9Uvyo1on4bxEBNaEjmSHshAOt9Seps5Y7AhxYKwpoMUDq12dsyD3GNkhcirdKAO13uRzKzviXCOprIl8X+icMgtwMCsdqwbuXo0qV6cATZyHJyos/uHBNPDOEV15+SzA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772446735; c=relaxed/simple; bh=AzI5Ae/Nc2f7GDhwHjvhiTKxWEZ8clztvctCM8lf4tI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dw9H4xrAJxXVuGos/24dHzQ3C712XQM0qp8HgY0PsxvcnsSs3zCxB7iHw2qoKeEWnbwEQ0srOCuaUFJPj5Vnxlv7hfUg914iSaupG56GFz4VaRdNil1Qf7Ozh7xUk3SB32gPaBMncl5qmTQRAmwRIAFQUaN/BqMdVlRIKoSTSYc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=runbox.com; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b=lTAGTmZC; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=runbox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b="lTAGTmZC" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vx0MV-003Bbo-8A; Mon, 02 Mar 2026 11:18:51 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector2; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To :Message-Id:Date:Subject:Cc:To:From; bh=2BKNgWMOvsEhkPs71HgPoPRLvfN6gLA0Noe+4f2IkL0=; b=lTAGTmZCWLzv+W4bYHX/4obzUF CBdXXCQ9nUTzuupZHZO1fP1DJpUTT9IkePlsFOOJQeMzldIMqxlQRdk1+AW1/iOhp3Ku5t0Nl1FaI 9RYDwrRdSByMn3XEcg4idinxUboi+CUDsO5krrhHFqdJ8ZkZOhKsL5SNJJ2xJU/fIoMyHqFjuia6D 3apT+O3D57q8MQYScuo6YQ9O+6sg8SyyfzSMUKdShbPP5aj2Se/BTEkiTzXVsT28WsAW2+/kXKUt1 gkfidNzEDNIzS0CNNAqnRLWXW9L5X/23FCsiKvxBPrxsBtXlB7HTzae0HkPX/LSzCJ0OZJirjPgIb q9c30jpw==; Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vx0MU-0002yR-Sw; Mon, 02 Mar 2026 11:18:51 +0100 Received: by submission01.runbox with esmtpsa [Authenticated ID (1493616)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1vx0MC-006y7o-LO; Mon, 02 Mar 2026 11:18:32 +0100 From: david.laight.linux@gmail.com To: Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kernel@vger.kernel.org, Cheng Li Cc: David Laight Subject: [PATCH v4 next 16/23] tools/nolibc/printf: Handle "%s" with the numeric formats Date: Mon, 2 Mar 2026 10:18:08 +0000 Message-Id: <20260302101815.3043-17-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260302101815.3043-1-david.laight.linux@gmail.com> References: <20260302101815.3043-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Laight Avoids the extra va_arg() call with is non-trivial on a lot of modern ABI. Signed-off-by: David Laight --- Unchanched for v4. Changes for v3: - Moved to its own patch (part of patch 7 in v2).. - Fix 32bit compile. tools/include/nolibc/stdio.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 4c7626dbd63f..484432ca87d5 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -412,13 +412,13 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list */ ch_flag = _NOLIBC_PF_FLAG(ch); if (((ch >= 'a' && ch <= 'z') || ch == 'X') && - _NOLIBC_PF_FLAGS_CONTAIN(ch_flag, 'c', 'd', 'i', 'u', 'x', 'p')) { - /* 'long' is needed for pointer conversions and ltz lengths. + _NOLIBC_PF_FLAGS_CONTAIN(ch_flag, 'c', 'd', 'i', 'u', 'x', 'p', 's')) { + /* 'long' is needed for pointer/string conversions and ltz lengths. * A single test can be used provided 'p' (the same bit as '0') * is masked from flags. */ if (_NOLIBC_PF_FLAGS_CONTAIN(ch_flag | (flags & ~_NOLIBC_PF_FLAG('p')), - 'p', 'l', 't', 'z')) { + 'p', 's', 'l', 't', 'z')) { v = va_arg(args, unsigned long); signed_v = (long)v; } else if (_NOLIBC_PF_FLAGS_CONTAIN(flags, 'j', 'q')) { @@ -437,6 +437,15 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list goto do_output; } + if (ch == 's') { + /* "%s" - character string. */ + outstr = (const char *)(uintptr_t)v; + if (!outstr) { + outstr = "(null)"; + } + goto do_strlen_output; + } + out = outbuf; if (_NOLIBC_PF_FLAGS_CONTAIN(ch_flag, 'd', 'i')) { @@ -465,13 +474,6 @@ int __nolibc_printf(__nolibc_printf_cb cb, void *state, const char *fmt, va_list goto do_strlen_output; } - if (ch == 's') { - outstr = va_arg(args, char *); - if (!outstr) - outstr="(null)"; - goto do_strlen_output; - } - if (ch == 'm') { #ifdef NOLIBC_IGNORE_ERRNO outstr = "unknown error"; -- 2.39.5