[PATCH 08/13] gdb/dwarf2: remove uses of sprintf
Andrew Burgess
aburgess@redhat.com
Mon Aug 17 16:35:05 GMT 2026
Simon Marchi <simon.marchi@efficios.com> writes:
> When building on macOS, I get some:
>
> /Users/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:3773: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]
> 3773 | sprintf (buf, "TU %s at offset %s", hex_string (sig_type->signature),
> | ^
>
> Replace them with xsnprintf, which takes the destination size and asserts
> that the output was not truncated.
Approved-By: Andrew Burgess <aburgess@redhat.com>
Thanks,
Andrew
>
> Change-Id: Ie0324f75e5d4aad9b647007848459bf4af5998a6
> ---
> gdb/dwarf2/read.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> index ca475f53745d..a8b99425554a 100644
> --- a/gdb/dwarf2/read.c
> +++ b/gdb/dwarf2/read.c
> @@ -3770,15 +3770,16 @@ process_queue (dwarf2_per_objfile *per_objfile)
> if (signatured_type *sig_type = per_cu->as_signatured_type ();
> sig_type != nullptr)
> {
> - sprintf (buf, "TU %s at offset %s", hex_string (sig_type->signature),
> - sect_offset_str (per_cu->sect_off ()));
> + xsnprintf (buf, sizeof (buf), "TU %s at offset %s",
> + hex_string (sig_type->signature),
> + sect_offset_str (per_cu->sect_off ()));
> /* There can be 100s of TUs. Only print them in verbose mode. */
> debug_print_threshold = 2;
> }
> else
> {
> - sprintf (buf, "CU at offset %s",
> - sect_offset_str (per_cu->sect_off ()));
> + xsnprintf (buf, sizeof (buf), "CU at offset %s",
> + sect_offset_str (per_cu->sect_off ()));
> debug_print_threshold = 1;
> }
>
> --
> 2.55.0
More information about the Binutils
mailing list