From: Mark Wielaard Date: Tue, 30 Apr 2024 14:39:17 +0000 (+0200) Subject: ar: Replace one alloca use by xmalloc X-Git-Tag: elfutils-0.192~90 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3c71cab7c5bfba0549d0a1716e7061d07eafd794;p=thirdparty%2Felfutils.git ar: Replace one alloca use by xmalloc 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 --- diff --git a/src/ar.c b/src/ar.c index e6d6d58f..fcb8bfb9 100644 --- a/src/ar.c +++ b/src/ar.c @@ -41,6 +41,7 @@ #include #include +#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; }