]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
tests: Pull new_data_buf() into file scope for elfstrmerge.
authorTimm Bäder <tbaeder@redhat.com>
Wed, 17 Feb 2021 08:46:05 +0000 (09:46 +0100)
committerMark Wielaard <mark@klomp.org>
Mon, 1 Mar 2021 22:31:44 +0000 (23:31 +0100)
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
tests/ChangeLog
tests/elfstrmerge.c

index 83501344ccd5cddbc2644f9d2d122a5dca196db5..bb842cb57195987d737638fca022e55e720e8198 100644 (file)
@@ -1,3 +1,9 @@
+2021-02-17  Timm Bäder  <tbaeder@redhat.com>
+
+       * elfstrmerge.c (main): Move new_data_buf function to...
+       (new_data_buf): ...top-level static function adding fname,
+       ndx, shdrstrnd and shdrnum as arguments.
+
 2021-02-17  Timm Bäder  <tbaeder@redhat.com>
 
        * elfstrmerge.c (main): Move newsecndx function to...
index 00f025ece732e2bf321b21777f34579c8a9ee05a..197c6a5d8e17fe1e17929fb5732c0f91f735ce6e 100644 (file)
@@ -174,6 +174,20 @@ newsecndx (size_t secndx, size_t shdrstrndx, size_t shdrnum,
   return secndx < shdrstrndx ? secndx : secndx - 1;
 }
 
+static void
+new_data_buf (Elf_Data *d, const char *fname,
+             size_t ndx, size_t shdrstrndx, size_t shdrnum)
+{
+  size_t s = d->d_size;
+  if (s == 0)
+    fail_idx ("Expected data in section", fname, ndx);
+  void *b = malloc (d->d_size);
+  if (b == NULL)
+    fail_idx ("Couldn't allocated buffer for section", NULL, ndx);
+  newscnbufs[newsecndx (ndx, shdrstrndx, shdrnum, fname,
+                       "section", ndx, "d_buf", 0)] = d->d_buf = b;
+}
+
 int
 main (int argc, char **argv)
 {
@@ -480,18 +494,6 @@ main (int argc, char **argv)
         manipulate the original data.  Allocate and check here, so we
         have a list of all data buffers we might need to release when
         done.  */
-      void new_data_buf (Elf_Data *d)
-      {
-       size_t s = d->d_size;
-       if (s == 0)
-         fail_idx ("Expected data in section", fname, ndx);
-       void *b = malloc (d->d_size);
-       if (b == NULL)
-         fail_idx ("Couldn't allocated buffer for section", NULL, ndx);
-       newscnbufs[newsecndx (ndx, shdrstrndx, shdrnum, fname,
-                             "section", ndx, "d_buf", 0)] = d->d_buf = b;
-      }
-
       Elf_Data *newdata = elf_newdata (newscn);
       if (newdata == NULL)
        fail_elf_idx ("Couldn't create new data for section", fnew, ndx);
@@ -518,7 +520,7 @@ main (int argc, char **argv)
                const bool update_name = shdr->sh_link == strtabndx;
                if (update_name && ndx != symtabndx)
                  fail ("Only one symbol table using strtab expected", fname);
-               new_data_buf (newdata);
+               new_data_buf (newdata, fname, ndx, shdrstrndx, shdrnum);
                size_t syms = (data->d_size
                               / gelf_fsize (elf, ELF_T_SYM, 1, EV_CURRENT));
                for (size_t i = 0; i < syms; i++)
@@ -549,7 +551,7 @@ main (int argc, char **argv)
 
            case SHT_GROUP:
              {
-               new_data_buf (newdata);
+               new_data_buf (newdata, fname, ndx, shdrstrndx, shdrnum);
                /* A section group contains Elf32_Words. The first
                   word is a flag value, the rest of the words are
                   indexes of the sections belonging to the group.  */
@@ -567,7 +569,7 @@ main (int argc, char **argv)
 
            case SHT_SYMTAB_SHNDX:
              {
-               new_data_buf (newdata);
+               new_data_buf (newdata, fname, ndx, shdrstrndx, shdrnum);
                /* A SHNDX just contains an array of section indexes
                   for the corresponding symbol table.  The entry is
                   SHN_UNDEF unless the corresponding symbol is