From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7932) id 8A3093857706; Mon, 28 Aug 2023 17:15:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A3093857706 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693242914; bh=/oM+Yqm0O9huTU89ON6JphC4z7h7rCNICMdpJNc/JT8=; h=From:To:Subject:Date:From; b=HT66k5bzGLso7wkyt121iNuxiBCeviIaOOVQ5VSNB3+xlo9e9TsGqBh7thaakXvf4 htdkPlXU8iqkpYdKS5dx+HOTm+Fh46LKmMpT9Y+vRV1WlaEK7vi0z5gVN54kvNj01v mMDW5CmVWbtejWFqniXuq6bZ+MotJee4dTbMqbBA= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Joe Simmons-Talbott To: glibc-cvs@sourceware.org Subject: [glibc] argp-parse: Get rid of alloca X-Act-Checkin: glibc X-Git-Author: Joe Simmons-Talbott X-Git-Refname: refs/heads/master X-Git-Oldrev: 4d8b09393354f6ce079f399df5b84abf0db894b5 X-Git-Newrev: 46924663bd1650ace91d5afd7b2906999cb443de Message-Id: <20230828171514.8A3093857706@sourceware.org> Date: Mon, 28 Aug 2023 17:15:14 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=46924663bd1650ace91d5afd7b2906999cb443de commit 46924663bd1650ace91d5afd7b2906999cb443de Author: Joe Simmons-Talbott Date: Mon Aug 28 16:49:02 2023 +0000 argp-parse: Get rid of alloca Even though the alloca usage is relatively small and fixed size the code can be written without using alloca. Convert to local variables. Checked on x86_64-linux-gnu. Reviewed-by: Adhemerval Zanella Diff: --- argp/argp-parse.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/argp/argp-parse.c b/argp/argp-parse.c index a44b50f8e4..1ff2612aeb 100644 --- a/argp/argp-parse.c +++ b/argp/argp-parse.c @@ -21,21 +21,6 @@ #include #endif -/* AIX requires this to be the first thing in the file. */ -#ifndef __GNUC__ -# if HAVE_ALLOCA_H || defined _LIBC -# include -# else -# ifdef _AIX -#pragma alloca -# else -# ifndef alloca /* predefined by HP cc +Olibcalls */ -char *alloca (); -# endif -# endif -# endif -#endif - #include #include #include @@ -884,6 +869,9 @@ __argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, error_t err; struct parser parser; + struct argp_child child[4]; + struct argp top_argp; + /* If true, then err == EBADKEY is a result of a non-option argument failing to be parsed (which in some cases isn't actually an error). */ int arg_ebadkey = 0; @@ -891,24 +879,23 @@ __argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, if (! (flags & ARGP_NO_HELP)) /* Add our own options. */ { - struct argp_child *child = alloca (4 * sizeof (struct argp_child)); - struct argp *top_argp = alloca (sizeof (struct argp)); + int child_index = 0; /* TOP_ARGP has no options, it just serves to group the user & default argps. */ - memset (top_argp, 0, sizeof (*top_argp)); - top_argp->children = child; + memset (&top_argp, 0, sizeof (struct argp)); + top_argp.children = child; memset (child, 0, 4 * sizeof (struct argp_child)); if (argp) - (child++)->argp = argp; - (child++)->argp = &argp_default_argp; + child[child_index++].argp = argp; + child[child_index++].argp = &argp_default_argp; if (argp_program_version || argp_program_version_hook) - (child++)->argp = &argp_version_argp; - child->argp = 0; + child[child_index++].argp = &argp_version_argp; + child[child_index].argp = 0; - argp = top_argp; + argp = &top_argp; } /* Construct a parser for these arguments. */