diff options
author | Tsukasa OI <research_trasio@irq.a4lg.com> | 2022-10-06 06:43:51 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2022-10-11 15:18:14 +0100 |
commit | 96894c19ad2b91db76b9b606d48c56ad354b4801 (patch) | |
tree | 06ec6e55b3d9f2fff45fd33b909b8221e5dbd867 /sim/common/sim-hw.c | |
parent | 25ae9e265976b45897865d14ed454ec3c937bd78 (diff) | |
download | gdb-96894c19ad2b91db76b9b606d48c56ad354b4801.zip gdb-96894c19ad2b91db76b9b606d48c56ad354b4801.tar.gz gdb-96894c19ad2b91db76b9b606d48c56ad354b4801.tar.bz2 |
sim: Suppress non-literal printf warning
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 <aburgess@redhat.com>
Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
Diffstat (limited to 'sim/common/sim-hw.c')
-rw-r--r-- | sim/common/sim-hw.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/sim/common/sim-hw.c b/sim/common/sim-hw.c index cece563..7bfe91e 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 != 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 |