From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sender-0.a4lg.com (mail-sender-0.a4lg.com [IPv6:2401:2500:203:30b:4000:6bfe:4757:0]) by sourceware.org (Postfix) with ESMTPS id 5F349384B823 for ; Thu, 6 Oct 2022 06:44:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5F349384B823 Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 7609C300089; Thu, 6 Oct 2022 06:44:30 +0000 (UTC) From: Tsukasa OI To: Tsukasa OI , Andrew Burgess , Mike Frysinger Cc: gdb-patches@sourceware.org Subject: [PATCH v3 3/5] sim: Suppress non-literal printf warning Date: Thu, 6 Oct 2022 06:43:51 +0000 Message-Id: <1e125faf59c101508372275aa7b9d00b8d32a7e9.1665038297.git.research_trasio@irq.a4lg.com> In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Oct 2022 06:44:33 -0000 Clang generates a warning if the format string of a printf-like function is not a literal ("-Wformat-nonliteral"). On the default configuration, it causes a build failure (unless "--disable-werror" is specified). To avoid this warning, this commit now uses vsnprintf to format error message and pass the message to sim_engine_abort function with another printf-style formatting. This patch is mostly authored by Andrew Burgess and slightly modified by Tsukasa OI. Co-authored-by: Andrew Burgess Signed-off-by: Tsukasa OI --- sim/common/sim-hw.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/sim/common/sim-hw.c b/sim/common/sim-hw.c index cece5638bc9..c70770893c9 100644 --- a/sim/common/sim-hw.c +++ b/sim/common/sim-hw.c @@ -403,13 +403,16 @@ sim_hw_io_write_buffer (struct sim_state *sd, /* Abort the simulation specifying HW as the reason */ -void +void ATTRIBUTE_PRINTF (2, 0) hw_vabort (struct hw *me, const char *fmt, va_list ap) { + int len; const char *name; char *msg; + va_list cpy; + /* find an identity */ if (me != NULL && hw_path (me) != NULL && hw_path (me) [0] != '\0') name = hw_path (me); @@ -419,16 +422,19 @@ hw_vabort (struct hw *me, name = hw_family (me); else name = "device"; - /* construct an updated format string */ - msg = alloca (strlen (name) + strlen (": ") + strlen (fmt) + 1); - strcpy (msg, name); - strcat (msg, ": "); - strcat (msg, fmt); + + /* Expand FMT and AP into MSG buffer. */ + va_copy (cpy, ap); + len = vsnprintf (NULL, 0, fmt, cpy) + 1; + va_end (cpy); + msg = alloca (len); + vsnprintf (msg, len, fmt, ap); + /* report the problem */ - sim_engine_vabort (hw_system (me), - STATE_HW (hw_system (me))->cpu, - STATE_HW (hw_system (me))->cia, - msg, ap); + sim_engine_abort (hw_system (me), + STATE_HW (hw_system (me))->cpu, + STATE_HW (hw_system (me))->cia, + "%s: %s", name, msg); } void -- 2.34.1