From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QBnQHGl5PmMCeQYAWB0awg (envelope-from ) for ; Thu, 06 Oct 2022 02:44:57 -0400 Received: by simark.ca (Postfix, from userid 112) id 740171E112; Thu, 6 Oct 2022 02:44:57 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=EnXNV8Qx; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 2CE081E0CB for ; Thu, 6 Oct 2022 02:44:57 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D1EF738654A2 for ; Thu, 6 Oct 2022 06:44:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1EF738654A2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665038696; bh=/XtFy6Tt7TywaHRnw1TXlJp8MRQOtEISVR2BdoZE4AA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=EnXNV8Qx6VqRj1QnggEXy10s2/H9oef3pbKgVqamOZXVMOEyyjxZ4C4tRZK3+U9gX 4H5I5Wbr5uGCwjKqdq3TtdnIcpPZnsHLQ2vi7HeUQDjUixDPb7Huu7HKTtFkQVscDJ askqG4ErZWSTUIodFhwvEJgQZWO4Lm80Xkcv6EAM= 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) To: Tsukasa OI , Andrew Burgess , Mike Frysinger 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-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: , From: Tsukasa OI via Gdb-patches Reply-To: Tsukasa OI Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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