]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Use xasprintf instead of asprintf followed by error(EXIT_FAILURE)
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 6 Sep 2021 10:00:00 +0000 (10:00 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 9 Sep 2021 08:03:00 +0000 (08:03 +0000)
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
lib/ChangeLog
lib/color.c
src/ChangeLog
src/objdump.c
src/readelf.c
src/unstrip.c

index 468001f8c47df9e5a1cc888efe811d9109b4c413..96eaa33012d4a8e5598ef1970ec0b00fd632ced4 100644 (file)
@@ -1,5 +1,8 @@
 2021-09-06  Dmitry V. Levin  <ldv@altlinux.org>
 
+       * color.c (parse_opt): Replace asprintf followed by error(EXIT_FAILURE)
+       with xasprintf.
+
        * xasprintf.c: New file.
        * Makefile.am (libeu_a_SOURCES): Add it.
        * libeu.h (xasprintf): New prototype.
index 454cb7caa179b2391775b3491d2538e272099cc3..e43b614397aefdd1b5589296838245029c13838f 100644 (file)
@@ -188,10 +188,8 @@ valid arguments are:\n\
                            if (name_len == known[i].len
                                && memcmp (start, known[i].name, name_len) == 0)
                              {
-                               if (asprintf (known[i].varp, "\e[%.*sm",
-                                             (int) (env - val), val) < 0)
-                                 error (EXIT_FAILURE, errno,
-                                        _("cannot allocate memory"));
+                               *known[i].varp =
+                                 xasprintf ("\e[%.*sm", (int) (env - val), val);
                                break;
                              }
                        }
index 1e7968f454328572969956987a72137943de7234..e8fce200bf0ace01baa1b759b86dc8c748549b39 100644 (file)
@@ -1,5 +1,10 @@
 2021-09-06  Dmitry V. Levin  <ldv@altlinux.org>
 
+       * objdump.c (show_disasm): Replace asprintf followed by
+       error(EXIT_FAILURE) with xasprintf.
+       * readelf.c (handle_gnu_hash): Likewise.
+       * unstrip.c (handle_output_dir_module, main): Likewise.
+
        * elflint.c (check_sections): Remove cast of xcalloc return value.
        * findtextrel.c (process_file): Remove casts of malloc and realloc
        return values.
index 3a93248c49b2159ebda4818e805d37d082fe1dca..f7ea6c92c82267ca3bd01782992426817f2b66c1 100644 (file)
@@ -717,15 +717,14 @@ show_disasm (Ebl *ebl, const char *fname, uint32_t shstrndx)
              info.address_color = color_address;
              info.bytes_color = color_bytes;
 
-             if (asprintf (&fmt, "%s%%7m %s%%.1o,%s%%.2o,%s%%.3o,,%s%%.4o%s%%.5o%%34a %s%%l",
-                           color_mnemonic ?: "",
-                           color_operand1 ?: "",
-                           color_operand2 ?: "",
-                           color_operand3 ?: "",
-                            color_operand4 ?: "",
-                            color_operand5 ?: "",
-                           color_label ?: "") < 0)
-               error (EXIT_FAILURE, errno, _("cannot allocate memory"));
+             fmt = xasprintf ("%s%%7m %s%%.1o,%s%%.2o,%s%%.3o,,%s%%.4o%s%%.5o%%34a %s%%l",
+                              color_mnemonic ?: "",
+                              color_operand1 ?: "",
+                              color_operand2 ?: "",
+                              color_operand3 ?: "",
+                              color_operand4 ?: "",
+                              color_operand5 ?: "",
+                              color_label ?: "");
            }
          else
            {
index 1e3ad43d0cbcbf5cf13a2aacb04cca184b02fd80..3a199068697b5587db7d3d0f8eee20c207f64fb9 100644 (file)
@@ -3448,17 +3448,15 @@ handle_gnu_hash (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, size_t shstrndx)
       nbits += (word & 0x0000ffff) + ((word >> 16) & 0x0000ffff);
     }
 
-  char *str;
-  if (unlikely (asprintf (&str, _("\
+  char *str = xasprintf (_("\
  Symbol Bias: %u\n\
  Bitmask Size: %zu bytes  %" PRIuFAST32 "%% bits set  2nd hash shift: %u\n"),
-                         (unsigned int) symbias,
-                         bitmask_words * sizeof (Elf32_Word),
-                         ((nbits * 100 + 50)
-                          / (uint_fast32_t) (bitmask_words
+                        (unsigned int) symbias,
+                        bitmask_words * sizeof (Elf32_Word),
+                        ((nbits * 100 + 50)
+                         / (uint_fast32_t) (bitmask_words
                                              * sizeof (Elf32_Word) * 8)),
-                         (unsigned int) shift) == -1))
-    error (EXIT_FAILURE, 0, _("memory exhausted"));
+                         (unsigned int) shift);
 
   print_hash_info (ebl, scn, shdr, shstrndx, maxlength, nbucket, nsyms,
                   lengths, str);
index 6618ec9bf4715c4c44ca043582b098a75b3cc04d..aacc9aad55f79bdf52501cd7fda7de2c110086a9 100644 (file)
@@ -2401,9 +2401,7 @@ handle_output_dir_module (const char *output_dir, Dwfl_Module *mod, bool force,
   if (file == NULL && ignore)
     return;
 
-  char *output_file;
-  if (asprintf (&output_file, "%s/%s", output_dir, modnames ? name : file) < 0)
-    error (EXIT_FAILURE, 0, _("memory exhausted"));
+  char *output_file = xasprintf ("%s/%s", output_dir, modnames ? name : file);
 
   handle_dwfl_module (output_file, true, force, mod, all, ignore, relocate);
 
@@ -2606,9 +2604,7 @@ or - if no debuginfo was found, or . if FILE contains the debug information.\
 
       if (info.output_dir != NULL)
        {
-         char *file;
-         if (asprintf (&file, "%s/%s", info.output_dir, info.args[0]) < 0)
-           error (EXIT_FAILURE, 0, _("memory exhausted"));
+         char *file = xasprintf ("%s/%s", info.output_dir, info.args[0]);
          handle_explicit_files (file, true, info.force,
                                 info.args[0], info.args[1]);
          free (file);