From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id D162038582B7; Tue, 11 Oct 2022 14:19:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D162038582B7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665497966; bh=9OyJ1taE+dKH+wbwiP+aQkvi8QdMuvHiVqA5kAMkxqE=; h=From:To:Subject:Date:From; b=LXLxa1Y8voc/krfTQ8pntpsRD8lMDY0NbFsEzWNI0gvQEkff8KfrUs1iaqMnQuaxn IXB3Xi68G8DOj6u1c9Sku2NkC5ceZalXgQi3tqpqANgNNymMGVFAbeSNNh7a1MySp4 F1Lp9tO07k3vKeMt4hLQTal/6sq+BKJ1AlWDVijk= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] sim: Suppress non-literal printf warning X-Act-Checkin: binutils-gdb X-Git-Author: Tsukasa OI X-Git-Refname: refs/heads/master X-Git-Oldrev: 25ae9e265976b45897865d14ed454ec3c937bd78 X-Git-Newrev: 96894c19ad2b91db76b9b606d48c56ad354b4801 Message-Id: <20221011141926.D162038582B7@sourceware.org> Date: Tue, 11 Oct 2022 14:19:26 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D96894c19ad2b= 91db76b9b606d48c56ad354b4801 commit 96894c19ad2b91db76b9b606d48c56ad354b4801 Author: Tsukasa OI Date: Thu Oct 6 06:43:51 2022 +0000 sim: Suppress non-literal printf warning =20 Clang generates a warning if the format string of a printf-like functio= n is not a literal ("-Wformat-nonliteral"). On the default configuration, it causes a build failure (unless "--disable-werror" is specified). =20 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. =20 This patch is mostly authored by Andrew Burgess and slightly modified by Tsukasa OI. =20 Co-authored-by: Andrew Burgess Signed-off-by: Tsukasa OI Diff: --- sim/common/hw-device.h | 6 ++---- sim/common/sim-hw.c | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/sim/common/hw-device.h b/sim/common/hw-device.h index 7a36f2f518c..451f88723de 100644 --- a/sim/common/hw-device.h +++ b/sim/common/hw-device.h @@ -437,10 +437,8 @@ void hw_abort const char *fmt, ...) ATTRIBUTE_PRINTF (2, 3) ATTRIBUTE_NORETURN; =20 -void hw_vabort -(struct hw *me, - const char *fmt, - va_list ap) ATTRIBUTE_NORETURN; +extern void hw_vabort (struct hw *me, const char *fmt, va_list ap) + ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 0); =20 void hw_halt (struct hw *me, diff --git a/sim/common/sim-hw.c b/sim/common/sim-hw.c index cece5638bc9..7bfe91e4ae2 100644 --- a/sim/common/sim-hw.c +++ b/sim/common/sim-hw.c @@ -408,8 +408,11 @@ 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 !=3D NULL && hw_path (me) !=3D NULL && hw_path (me) [0] !=3D '\0') name =3D hw_path (me); @@ -419,16 +422,19 @@ hw_vabort (struct hw *me, name =3D hw_family (me); else name =3D "device"; - /* construct an updated format string */ - msg =3D 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 =3D vsnprintf (NULL, 0, fmt, cpy) + 1; + va_end (cpy); + msg =3D 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); } =20 void