[binutils-gdb] gdb/elfread: remove use of sprintf
Simon Marchi via Gdb-cvs <[email protected]>
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=27e4e8af3ad033edd5f10517346c12db7d2373e1 commit 27e4e8af3ad033edd5f10517346c12db7d2373e1 Author: Simon Marchi <[email protected]> Date: Mon Aug 17 11:16:14 2026 -0400 gdb/elfread: remove use of sprintf 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. Change-Id: I296e25c863463ef05eca582c8303557570d63cf0 Approved-By: Andrew Burgess <[email protected]> Diff: --- gdb/elfread.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/gdb/elfread.c b/gdb/elfread.c index e3890ae0270..fcbd0176d08 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)) {