From c3c04ffeba90ee4f73bec92997be07e41ac6abf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Thu, 13 Feb 2020 16:39:31 +0100 Subject: [PATCH] Remove use of alloca in setoptval * src/init.c (setoptval): Remove use of alloca * src/init.h: Add define MAX_LONGOPTION * src/main.c (struct cmdline_option): Make 'long_name' a char array --- src/init.c | 5 ++--- src/init.h | 2 ++ src/main.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/init.c b/src/init.c index eae5391b..062564c2 100644 --- a/src/init.c +++ b/src/init.c @@ -946,9 +946,8 @@ void setoptval (const char *com, const char *val, const char *optname) { /* Prepend "--" to OPTNAME. */ - char *dd_optname = (char *) alloca (2 + strlen (optname) + 1); - dd_optname[0] = '-'; - dd_optname[1] = '-'; + char dd_optname[2 + MAX_LONGOPTION + 1] = "--"; + strcpy (dd_optname + 2, optname); assert (val != NULL); diff --git a/src/init.h b/src/init.h index a0198f5b..af6a06b2 100644 --- a/src/init.h +++ b/src/init.h @@ -42,4 +42,6 @@ void cleanup (void); void defaults (void); bool run_wgetrc (const char *file, file_stats_t *); +#define MAX_LONGOPTION 26 + #endif /* INIT_H */ diff --git a/src/main.c b/src/main.c index 3b6e49fc..be8798ed 100644 --- a/src/main.c +++ b/src/main.c @@ -242,7 +242,7 @@ _Noreturn static void print_version (void); #endif struct cmdline_option { - const char *long_name; + char long_name[MAX_LONGOPTION]; char short_name; enum { OPT_VALUE,