]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
ar: Replace one alloca use by xmalloc
authorMark Wielaard <mark@klomp.org>
Tue, 30 Apr 2024 14:39:17 +0000 (16:39 +0200)
committerMark Wielaard <mark@klomp.org>
Sun, 12 May 2024 21:48:39 +0000 (23:48 +0200)
This alloca use is inside a lexical block and is used to replace one
element of argv. Use a function local variable, xmalloc and free to
make memory usage pattern more clear.

    * src/ar.c (main): Move newp char pointer declaration up.
    Use xmalloc to allocate space. free at end of main.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ar.c

index e6d6d58f2b3bc84b4728203e7e3bba708a443963..fcb8bfb90a9f8e3bbf92fc2a783e4489eb3c9441 100644 (file)
--- a/src/ar.c
+++ b/src/ar.c
@@ -41,6 +41,7 @@
 #include <system.h>
 #include <printversion.h>
 
+#include "libeu.h"
 #include "arlib.h"
 
 
@@ -154,10 +155,11 @@ main (int argc, char *argv[])
 
   /* For historical reasons the options in the first parameter need
      not be preceded by a dash.  Add it now if necessary.  */
+  char *newp = NULL;
   if (argc > 1 && argv[1][0] != '-')
     {
       size_t len = strlen (argv[1]) + 1;
-      char *newp = alloca (len + 1);
+      newp = (char *) xmalloc (len + 1);
       newp[0] = '-';
       memcpy (&newp[1], argv[1], len);
       argv[1] = newp;
@@ -271,6 +273,8 @@ MEMBER parameter required for 'a', 'b', and 'i' modifiers"));
       break;
     }
 
+  free (newp);
+
   return status;
 }