From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org, binutils@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 13/13] gdb/tracepoint: remove uses of sprintf
Date: Mon, 17 Aug 2026 11:16:18 -0400 [thread overview]
Message-ID: <20260817151646.152571-14-simon.marchi@efficios.com> (raw)
In-Reply-To: <20260817151646.152571-1-simon.marchi@efficios.com>
When building on macOS, I get some:
/Users/smarchi/src/binutils-gdb/gdb/tracepoint.c:1196:4: 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]
1196 | sprintf (end, "M-1,%s,%lX", phex_nz (m_memranges[i].start, 0),
| ^
Replace them with xsnprintf.
Change-Id: Id3ec76c47e5c0091fa3a028e36063b2115378e7e
---
gdb/tracepoint.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 798bb9a552d8..932a8f557e44 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -1164,6 +1164,9 @@ collection_list::stringify ()
gdb_printf ("\n");
if (!m_memranges.empty () && info_verbose)
gdb_printf ("Collecting memranges: \n");
+
+ char *buf_end = temp_buf.data () + temp_buf.size ();
+
for (i = 0, count = 0, end = temp_buf.data ();
i < m_memranges.size (); i++)
{
@@ -1193,11 +1196,12 @@ collection_list::stringify ()
"FFFFFFFF" (or more, depending on sizeof (unsigned)).
Special-case it. */
if (m_memranges[i].type == memrange_absolute)
- sprintf (end, "M-1,%s,%lX", phex_nz (m_memranges[i].start, 0),
- (long) length);
+ xsnprintf (end, buf_end - end, "M-1,%s,%lX",
+ phex_nz (m_memranges[i].start, 0), (long) length);
else
- sprintf (end, "M%X,%s,%lX", m_memranges[i].type,
- phex_nz (m_memranges[i].start, 0), (long) length);
+ xsnprintf (end, buf_end - end, "M%X,%s,%lX",
+ m_memranges[i].type, phex_nz (m_memranges[i].start, 0),
+ (long) length);
}
count += strlen (end);
@@ -1213,7 +1217,9 @@ collection_list::stringify ()
count = 0;
end = temp_buf.data ();
}
- sprintf (end, "X%08X,", (int) m_aexprs[i]->buf.size ());
+
+ xsnprintf (end, buf_end - end, "X%08X,",
+ (int) m_aexprs[i]->buf.size ());
end += 10; /* 'X' + 8 hex digits + ',' */
count += 10;
@@ -2816,11 +2822,14 @@ encode_source_string (int tpnum, ULONGEST addr,
{
if (80 + strlen (srctype) > buf_size)
error (_("Buffer too small for source encoding"));
- sprintf (buf, "%x:%s:%s:%x:%x:",
- tpnum, phex_nz (addr),
- srctype, 0, (int) strlen (src));
+
+ xsnprintf (buf, buf_size, "%x:%s:%s:%x:%x:",
+ tpnum, phex_nz (addr),
+ srctype, 0, (int) strlen (src));
+
if (strlen (buf) + strlen (src) * 2 >= buf_size)
error (_("Source string too long for buffer"));
+
bin2hex ((gdb_byte *) src, buf + strlen (buf), strlen (src));
return -1;
}
--
2.55.0
next prev parent reply other threads:[~2026-08-17 15:21 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
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 ` Simon Marchi [this message]
2026-08-17 16:51 ` [PATCH 13/13] gdb/tracepoint: " 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=20260817151646.152571-14-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=binutils@sourceware.org \
--cc=gdb-patches@sourceware.org \
/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