Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
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 09/13] gdb/elfread: remove use of sprintf
Date: Mon, 17 Aug 2026 17:38:07 +0100	[thread overview]
Message-ID: <87ecfw3dow.fsf@redhat.com> (raw)
In-Reply-To: <20260817151646.152571-10-simon.marchi@efficios.com>

Simon Marchi <simon.marchi@efficios.com> writes:

> When building on macOS, I get:
>
>     /Users/smarchi/src/binutils-gdb/gdb/elfread.c:813:3: 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]
>       813 |   sprintf (name_got_plt, "%s" SYMBOL_GOT_PLT_SUFFIX, name);
>           |   ^
>
> Change this use of sprintf with an std::string, which also allows
> getting rid of a use of alloca.

+1 for alloca removal!

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew


>
> Change-Id: I296e25c863463ef05eca582c8303557570d63cf0
> ---
>  gdb/elfread.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/gdb/elfread.c b/gdb/elfread.c
> index e3890ae0270c..fcbd0176d08f 100644
> --- a/gdb/elfread.c
> +++ b/gdb/elfread.c
> @@ -804,20 +804,17 @@ static int
>  elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
>  {
>    gnu_ifunc_debug_printf ("resolving \"%s\" by GOT", name);
> -  char *name_got_plt;
> -  const size_t got_suffix_len = strlen (SYMBOL_GOT_PLT_SUFFIX);
>    int found = 0;
>    const char *func = __func__;
>  
> -  name_got_plt = (char *) alloca (strlen (name) + got_suffix_len + 1);
> -  sprintf (name_got_plt, "%s" SYMBOL_GOT_PLT_SUFFIX, name);
> +  std::string name_got_plt = std::string (name) + SYMBOL_GOT_PLT_SUFFIX;
>  
>    /* FIXME: we only search the initial namespace.
>  
>       To search other namespaces, we would need to provide context, e.g. in
>       form of an objfile in that namespace.  */
>    current_program_space->iterate_over_objfiles_in_search_order
> -    ([name, name_got_plt, &addr_p, &found, func] (struct objfile *objfile)
> +    ([name, &name_got_plt, &addr_p, &found, func] (struct objfile *objfile)
>         {
>  	 bfd *obfd = objfile->obfd.get ();
>  	 struct gdbarch *gdbarch = objfile->arch ();
> @@ -828,8 +825,8 @@ elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
>  	 gdb_byte *buf = (gdb_byte *) alloca (ptr_size);
>  
>  	 bound_minimal_symbol msym
> -	   = lookup_minimal_symbol (current_program_space, name_got_plt,
> -				    objfile);
> +	   = lookup_minimal_symbol (current_program_space,
> +				    name_got_plt.c_str (), objfile);
>  	 if (msym.minsym == NULL)
>  	   return 0;
>  	 if (msym.minsym->type () != mst_slot_got_plt)
> @@ -850,7 +847,8 @@ elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
>  	 addr = gdbarch_addr_bits_remove (gdbarch, addr);
>  
>  	 gnu_ifunc_debug_printf_func (func, "GOT entry \"%s\" points to %s",
> -				      name_got_plt, paddress (gdbarch, addr));
> +				      name_got_plt.c_str (),
> +				      paddress (gdbarch, addr));
>  
>  	 if (elf_gnu_ifunc_record_cache (name, addr))
>  	   {
> -- 
> 2.55.0


  reply	other threads:[~2026-08-17 16:39 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 [this message]
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=87ecfw3dow.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