From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B326C433F5 for ; Tue, 19 Apr 2022 00:45:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242530AbiDSAsI (ORCPT ); Mon, 18 Apr 2022 20:48:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241314AbiDSApQ (ORCPT ); Mon, 18 Apr 2022 20:45:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D57792CE30 for ; Mon, 18 Apr 2022 17:42:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A240A61426 for ; Tue, 19 Apr 2022 00:42:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 744C7C3411C; Tue, 19 Apr 2022 00:42:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650328948; bh=QdhjjxhJ7SHpqY5mdpkVbTMHi36forprWYIZSJUVTUg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IXlVRfSzb+anc4S3lOIYVHiLxrzgRwgawPoevA95ykPOFgD/8jWpEfPXfORtnab36 bt4alEe+xSuKwMXdxmsCOuxdC1h9A98vHdw3QS2dikLJC5GnKCbGFeiLvgxl6bO2PX XJ8bHMLtVLgWfFwop6OqXbiGV3Sjry4Mkva0VJu1/UXZRJAiRg3/WUuArNSwLtJef0 jNgxcJvnw++TCGFoN3bKnLfxrH+atK8Jl0AfZR0HX4k3P4aIr8nQ2Bcm7uVtJB7pV9 KEL+4d+kUC7wBeWmCbJFz32wYevUthVSoIWhLgbMVvypfLzbsz2wIyMd2tT0d1SsY5 bDTDrCUetCp6g== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 554FC5C3230; Mon, 18 Apr 2022 17:42:27 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@fb.com, w@lwt.eu, Willy Tarreau , "Paul E . McKenney" Subject: [PATCH nolibc 43/61] tools/nolibc/stdio: make printf(%s) accept NULL Date: Mon, 18 Apr 2022 17:42:07 -0700 Message-Id: <20220419004225.3952530-43-paulmck@kernel.org> X-Mailer: git-send-email 2.31.1.189.g2e36527f23 In-Reply-To: <20220419004219.GA3952301@paulmck-ThinkPad-P17-Gen-1> References: <20220419004219.GA3952301@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Willy Tarreau It's often convenient to support this, especially in test programs where a NULL may correspond to an allocation error or a non-existing value. Let's make printf("%s") support being passed a NULL. In this case it prints "(null)" like glibc's printf(). Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/include/nolibc/stdio.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index cb4d3ab3a565..559ebe052a75 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -220,6 +220,8 @@ int vfprintf(FILE *stream, const char *fmt, va_list args) } else if (c == 's') { outstr = va_arg(args, char *); + if (!outstr) + outstr="(null)"; } else if (c == '%') { /* queue it verbatim */ -- 2.31.1.189.g2e36527f23