From: Andrew Burgess <aburgess@redhat.com>
To: Simon Marchi <simon.marchi@efficios.com>,
gdb-patches@sourceware.org, binutils@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH 02/13] gdbsupport: remove uses of sprintf
Date: Mon, 17 Aug 2026 16:49:18 +0100 [thread overview]
Message-ID: <87mruk3fy9.fsf@redhat.com> (raw)
In-Reply-To: <20260817151646.152571-3-simon.marchi@efficios.com>
Simon Marchi <simon.marchi@efficios.com> writes:
> When building on macOS, I get some errors about the uses of sprintf:
>
> CXX xml-utils.o
> /Users/smarchi/src/binutils-gdb/gdbsupport/xml-utils.cc:91:8: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations]
> 91 | sprintf (str, "%d", va_arg (ap, int));
> | ^
>
> We know they are safe, because the 32 byte destination buffer is large
> enough for all conversions. But I also don't think it's a big deal to
> switch to xsnprintf to avoid these errors, and to catch any future
> error.
Approved-By: Andrew Burgess <aburgess@redhat.com>
Thanks,
Andrew
>
> Change-Id: If3531e1916e103dfccd0ec033639b14a2b6df3cf
> ---
> gdbsupport/xml-utils.cc | 35 +++++++++++++++++++----------------
> 1 file changed, 19 insertions(+), 16 deletions(-)
>
> diff --git a/gdbsupport/xml-utils.cc b/gdbsupport/xml-utils.cc
> index 13dc27499120..cec7281c9297 100644
> --- a/gdbsupport/xml-utils.cc
> +++ b/gdbsupport/xml-utils.cc
> @@ -88,52 +88,55 @@ string_xml_appendf (std::string &buffer, const char *format, ...)
> str = va_arg (ap, char *);
> break;
> case 'd':
> - sprintf (str, "%d", va_arg (ap, int));
> + xsnprintf (buf, sizeof (buf), "%d", va_arg (ap, int));
> break;
> case 'u':
> - sprintf (str, "%u", va_arg (ap, unsigned int));
> + xsnprintf (buf, sizeof (buf), "%u", va_arg (ap, unsigned int));
> break;
> case 'x':
> - sprintf (str, "%x", va_arg (ap, unsigned int));
> + xsnprintf (buf, sizeof (buf), "%x", va_arg (ap, unsigned int));
> break;
> case 'o':
> - sprintf (str, "%o", va_arg (ap, unsigned int));
> + xsnprintf (buf, sizeof (buf), "%o", va_arg (ap, unsigned int));
> break;
> case 'l':
> f++;
> switch (*f)
> {
> case 'd':
> - sprintf (str, "%ld", va_arg (ap, long));
> + xsnprintf (buf, sizeof (buf), "%ld", va_arg (ap, long));
> break;
> case 'u':
> - sprintf (str, "%lu", va_arg (ap, unsigned long));
> + xsnprintf (buf, sizeof (buf), "%lu",
> + va_arg (ap, unsigned long));
> break;
> case 'x':
> - sprintf (str, "%lx", va_arg (ap, unsigned long));
> + xsnprintf (buf, sizeof (buf), "%lx",
> + va_arg (ap, unsigned long));
> break;
> case 'o':
> - sprintf (str, "%lo", va_arg (ap, unsigned long));
> + xsnprintf (buf, sizeof (buf), "%lo",
> + va_arg (ap, unsigned long));
> break;
> case 'l':
> f++;
> switch (*f)
> {
> case 'd':
> - sprintf (str, "%" PRId64,
> - (int64_t) va_arg (ap, long long));
> + xsnprintf (buf, sizeof (buf), "%" PRId64,
> + (int64_t) va_arg (ap, long long));
> break;
> case 'u':
> - sprintf (str, "%" PRIu64,
> - (uint64_t) va_arg (ap, unsigned long long));
> + xsnprintf (buf, sizeof (buf), "%" PRIu64,
> + (uint64_t) va_arg (ap, unsigned long long));
> break;
> case 'x':
> - sprintf (str, "%" PRIx64,
> - (uint64_t) va_arg (ap, unsigned long long));
> + xsnprintf (buf, sizeof (buf), "%" PRIx64,
> + (uint64_t) va_arg (ap, unsigned long long));
> break;
> case 'o':
> - sprintf (str, "%" PRIo64,
> - (uint64_t) va_arg (ap, unsigned long long));
> + xsnprintf (buf, sizeof (buf), "%" PRIo64,
> + (uint64_t) va_arg (ap, unsigned long long));
> break;
> default:
> str = 0;
> --
> 2.55.0
next prev parent reply other threads:[~2026-08-17 15:49 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 15:16 [PATCH 00/13] Fix various warnings when building on macOS Simon Marchi
2026-08-17 15:16 ` [PATCH 01/13] gdbsupport: remove uses of vsprintf Simon Marchi
2026-08-17 15:47 ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 02/13] gdbsupport: remove uses of sprintf Simon Marchi
2026-08-17 15:49 ` Andrew Burgess [this message]
2026-08-17 15:16 ` [PATCH 03/13] opcodes/z80: remove use " Simon Marchi
2026-08-18 6:40 ` Jan Beulich
2026-08-18 16:48 ` Simon Marchi
2026-08-17 15:16 ` [PATCH 04/13] sim/ppc: make defines.h sed command portable Simon Marchi
2026-08-17 15:36 ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 05/13] sim/m32r: fix unused variable warning on non-Linux hosts Simon Marchi
2026-08-17 15:36 ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 06/13] sim/m32r: fix unused function warnings " Simon Marchi
2026-08-17 15:37 ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 07/13] gdb/csky: remove uses of sprintf Simon Marchi
2026-08-17 16:26 ` Andrew Burgess
2026-08-17 17:03 ` Simon Marchi
2026-08-17 20:50 ` Tom Tromey
2026-08-18 18:26 ` Simon Marchi
2026-08-17 15:16 ` [PATCH 08/13] gdb/dwarf2: " Simon Marchi
2026-08-17 16:35 ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 09/13] gdb/elfread: remove use " Simon Marchi
2026-08-17 16:38 ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 10/13] gdbsupport: add xstrcpy Simon Marchi
2026-08-17 16:45 ` Andrew Burgess
2026-08-17 17:30 ` Simon Marchi
2026-08-17 15:16 ` [PATCH 11/13] gdb/remote-fileio: remove uses of sprintf Simon Marchi
2026-08-17 16:53 ` Andrew Burgess
2026-08-17 15:16 ` [PATCH 12/13] gdb/remote: " Simon Marchi
2026-08-17 16:51 ` Andrew Burgess
2026-08-17 17:34 ` Simon Marchi
2026-08-17 15:16 ` [PATCH 13/13] gdb/tracepoint: " Simon Marchi
2026-08-17 16:51 ` Andrew Burgess
2026-08-17 20:52 ` [PATCH 00/13] Fix various warnings when building on macOS Tom Tromey
2026-08-18 18:10 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mruk3fy9.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=binutils@sourceware.org \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox