diff options
author | Alan Modra <amodra@gmail.com> | 2024-10-21 12:16:31 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2024-10-24 17:58:00 +1030 |
commit | 86b26b453f65404b29ce035a2eb3d62671aa0612 (patch) | |
tree | 97309863b4b131ebbb0915a6bc943e9aad681ef4 /binutils | |
parent | 8b5a212495371fbc9bea7f4ce6d632df3763723b (diff) | |
download | binutils-86b26b453f65404b29ce035a2eb3d62671aa0612.zip binutils-86b26b453f65404b29ce035a2eb3d62671aa0612.tar.gz binutils-86b26b453f65404b29ce035a2eb3d62671aa0612.tar.bz2 |
Replace uses of asprintf with xasprintf
xasprintf has a nicer interface and behaves like xmalloc as far as
memory is concerned, ie. no need to check a return status and the
program exits with an error on OOM.
binutils/
* dwarf.c (load_debug_sup_file): Replace asprintf with xasprintf.
* nm.c (get_elf_symbol_type, get_coff_symbol_type): Likewise.
* objdump.c (dump_ctf_indent_lines): Likewise.
* readelf.c (display_lto_symtab, dump_ctf_indent_lines): Likewise.
* windres.c (main): Likewise.
* configure.ac: Remove asprintf from AC_CHECK_DECLS.
* config.in: Regenerate.
* configure: Regenerate.
gas/
* config/tc-kvx.c (kvx_emit_single_noop): Simplify.
* config/tc-riscv.c (md_assemblef): Replace asprintf with xasprintf.
* read.c (s_nop, do_s_func): Likewise.
* stabs.c (stabs_generate_asm_func): Likewise.
(stabs_generate_asm_endfunc): Likewise.
* configure.ac: Remove asprintf from AC_CHECK_DECLS.
* config.in: Regenerate.
* configure: Regenerate.
ld/
* ldlang.c (lang_leave_overlay_section): Replace xmalloc+sprintf
with xasprintf. Localise vars.
* lexsup.c (parse_args): Replace asprintf with xasprintf.
* pe-dll.c (make_head, make_tail, make_one): Likewise.
(make_singleton_name_thunk, make_import_fixup_entry): Likewise.
(make_runtime_pseudo_reloc): Likewise.
(pe_create_runtime_relocator_reference): Likewise.
* configure.ac: Remove asprintf from AC_CHECK_DECLS.
* config.in: Regenerate.
* configure: Regenerate.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/config.in | 4 | ||||
-rwxr-xr-x | binutils/configure | 10 | ||||
-rw-r--r-- | binutils/configure.ac | 2 | ||||
-rw-r--r-- | binutils/dwarf.c | 28 | ||||
-rw-r--r-- | binutils/nm.c | 14 | ||||
-rw-r--r-- | binutils/objdump.c | 6 | ||||
-rw-r--r-- | binutils/readelf.c | 19 | ||||
-rw-r--r-- | binutils/windres.c | 5 |
8 files changed, 17 insertions, 71 deletions
diff --git a/binutils/config.in b/binutils/config.in index ee148c7..93ff046 100644 --- a/binutils/config.in +++ b/binutils/config.in @@ -50,10 +50,6 @@ */ #undef HAVE_DCGETTEXT -/* Define to 1 if you have the declaration of `asprintf', and to 0 if you - don't. */ -#undef HAVE_DECL_ASPRINTF - /* Define to 1 if you have the declaration of `environ', and to 0 if you don't. */ #undef HAVE_DECL_ENVIRON diff --git a/binutils/configure b/binutils/configure index ac3de5e..41e41c6 100755 --- a/binutils/configure +++ b/binutils/configure @@ -15708,16 +15708,6 @@ $as_echo "#define HAVE_GOOD_UTIME_H 1" >>confdefs.h fi -ac_fn_c_check_decl "$LINENO" "asprintf" "ac_cv_have_decl_asprintf" "$ac_includes_default" -if test "x$ac_cv_have_decl_asprintf" = xyes; then : - ac_have_decl=1 -else - ac_have_decl=0 -fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_ASPRINTF $ac_have_decl -_ACEOF ac_fn_c_check_decl "$LINENO" "environ" "ac_cv_have_decl_environ" "$ac_includes_default" if test "x$ac_cv_have_decl_environ" = xyes; then : ac_have_decl=1 diff --git a/binutils/configure.ac b/binutils/configure.ac index 06c88e0..31fab69 100644 --- a/binutils/configure.ac +++ b/binutils/configure.ac @@ -279,7 +279,7 @@ if test $bu_cv_header_utime_h = yes; then AC_DEFINE(HAVE_GOOD_UTIME_H, 1, [Does <utime.h> define struct utimbuf?]) fi -AC_CHECK_DECLS([asprintf, environ, getc_unlocked, stpcpy, strnlen]) +AC_CHECK_DECLS([environ, getc_unlocked, stpcpy, strnlen]) # Link in zlib/zstd if we can. This allows us to read compressed debug # sections. This is used only by readelf.c (objdump uses bfd for diff --git a/binutils/dwarf.c b/binutils/dwarf.c index 424353c..4b46100 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -12318,34 +12318,14 @@ load_debug_sup_file (const char * main_filename, void * file) } if (filename[0] != '/' && strchr (main_filename, '/')) - { - char * new_name; - int new_len; - - new_len = asprintf (& new_name, "%.*s/%s", + filename = xasprintf ("%.*s/%s", (int) (strrchr (main_filename, '/') - main_filename), main_filename, filename); - if (new_len < 3) - { - warn (_("unable to construct path for supplementary debug file\n")); - if (new_len > -1) - free (new_name); - return; - } - filename = new_name; - } else - { - /* PR 27796: Make sure that we pass a filename that can be free'd to - add_separate_debug_file(). */ - filename = strdup (filename); - if (filename == NULL) - { - warn (_("out of memory constructing filename for .debug_sup link\n")); - return; - } - } + /* PR 27796: Make sure that we pass a filename that can be free'd to + add_separate_debug_file(). */ + filename = xstrdup (filename); void * handle = open_debug_file (filename); if (handle == NULL) diff --git a/binutils/nm.c b/binutils/nm.c index 7acf9a2..2546dc5 100644 --- a/binutils/nm.c +++ b/binutils/nm.c @@ -433,7 +433,6 @@ static const char * get_elf_symbol_type (unsigned int type) { static char *bufp; - int n; switch (type) { @@ -448,13 +447,11 @@ get_elf_symbol_type (unsigned int type) free (bufp); if (type >= STT_LOPROC && type <= STT_HIPROC) - n = asprintf (&bufp, _("<processor specific>: %d"), type); + bufp = xasprintf (_("<processor specific>: %d"), type); else if (type >= STT_LOOS && type <= STT_HIOS) - n = asprintf (&bufp, _("<OS specific>: %d"), type); + bufp = xasprintf (_("<OS specific>: %d"), type); else - n = asprintf (&bufp, _("<unknown>: %d"), type); - if (n < 0) - fatal ("%s", xstrerror (errno)); + bufp = xasprintf (_("<unknown>: %d"), type); return bufp; } @@ -462,7 +459,6 @@ static const char * get_coff_symbol_type (const struct internal_syment *sym) { static char *bufp; - int n; switch (sym->n_sclass) { @@ -482,9 +478,7 @@ get_coff_symbol_type (const struct internal_syment *sym) } free (bufp); - n = asprintf (&bufp, _("<unknown>: %d/%d"), sym->n_sclass, sym->n_type); - if (n < 0) - fatal ("%s", xstrerror (errno)); + bufp = xasprintf (_("<unknown>: %d/%d"), sym->n_sclass, sym->n_type); return bufp; } diff --git a/binutils/objdump.c b/binutils/objdump.c index 3242546..4980929 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -4769,11 +4769,7 @@ dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED, char *s, void *arg) { const char *blanks = arg; - char *new_s; - - if (asprintf (&new_s, "%s%s", blanks, s) < 0) - return s; - return new_s; + return xasprintf ("%s%s", blanks, s); } /* Make a ctfsect suitable for ctf_bfdopen_ctfsect(). */ diff --git a/binutils/readelf.c b/binutils/readelf.c index 0f8dc1b..73163e0 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -14421,17 +14421,14 @@ display_lto_symtab (Filedata * filedata, return false; /* Look for extended data for the symbol table. */ - Elf_Internal_Shdr * ext = NULL; void * ext_data_orig = NULL; char * ext_data = NULL; char * ext_data_end = NULL; - char * ext_name = NULL; - - if (asprintf (& ext_name, ".gnu.lto_.ext_symtab.%s", - (section_name (filedata, section) - + sizeof (".gnu.lto_.symtab.") - 1)) > 0 - && ext_name != NULL /* Paranoia. */ - && (ext = find_section (filedata, ext_name)) != NULL) + char *ext_name = xasprintf (".gnu.lto_.ext_symtab.%s", + (section_name (filedata, section) + + sizeof (".gnu.lto_.symtab."))); + Elf_Internal_Shdr *ext = find_section (filedata, ext_name); + if (ext != NULL) { if (ext->sh_size < 3) error (_("LTO Symbol extension table '%s' is empty!\n"), @@ -16871,11 +16868,7 @@ dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED, char *s, void *arg) { const char *blanks = arg; - char *new_s; - - if (asprintf (&new_s, "%s%s", blanks, s) < 0) - return s; - return new_s; + return xasprintf ("%s%s", blanks, s); } /* Dump CTF errors/warnings. */ diff --git a/binutils/windres.c b/binutils/windres.c index 3f691d3..f0f6433 100644 --- a/binutils/windres.c +++ b/binutils/windres.c @@ -885,10 +885,7 @@ main (int argc, char **argv) case OPTION_PREPROCESSOR: if (strchr (optarg, ' ')) - { - if (asprintf (& preprocessor, "\"%s\"", optarg) == -1) - preprocessor = optarg; - } + preprocessor = xasprintf ("\"%s\"", optarg); else preprocessor = optarg; break; |