From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 57F4A3858417 for ; Mon, 28 Aug 2023 13:20:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 57F4A3858417 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693228837; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1JdocBSv1pG/+aDGxA5FnUf5L5/YLxxTDEAe1GUsAbo=; b=clmd75qCzssRWQQeMIWu8UGhNrhiveGDHeFAxHZQtJFyxKujHHyTKQe60M+UwFNkGcYOvt 836lsEMw/ne/ixd+tdgIefHoOtJLydmtaeyaZIugjK02JrQokL6yqtY36fPcmQVJHiuQRw gOyNTuV2qkHv06qHWMO5TLYyAY+POCA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-602-ZQMKBNpgMdSfVkBQ4VBAeA-1; Mon, 28 Aug 2023 09:20:35 -0400 X-MC-Unique: ZQMKBNpgMdSfVkBQ4VBAeA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F4EF805951 for ; Mon, 28 Aug 2023 13:20:35 +0000 (UTC) Received: from oak (unknown [10.22.33.147]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3ADB42026D4B for ; Mon, 28 Aug 2023 13:20:35 +0000 (UTC) Date: Mon, 28 Aug 2023 09:20:33 -0400 From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Subject: Re: [PATCH] argp-parse: Get rid of alloca Message-ID: <20230828132033.GT3849957@oak> References: <20230713124813.216028-1-josimmon@redhat.com> <20230803131049.GC3849957@oak> <20230815144912.GQ3849957@oak> MIME-Version: 1.0 In-Reply-To: <20230815144912.GQ3849957@oak> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Ping. On Tue, Aug 15, 2023 at 10:49:12AM -0400, Joe Simmons-Talbott via Libc-alpha wrote: > On Thu, Aug 03, 2023 at 09:10:49AM -0400, Joe Simmons-Talbott via Libc-alpha wrote: > > On Thu, Jul 13, 2023 at 08:48:13AM -0400, Joe Simmons-Talbott wrote: > > > Even though the alloca usage is relatively small and fixed size the code > > > can be written without using alloca. Convert to local variables. > > > > Ping. > Ping. > > Thanks, > Joe > > > > Thanks, > > Joe > > > > > > Checked on x86_64-linux-gnu. > > > --- > > > argp/argp-parse.c | 20 +++++++++++--------- > > > 1 file changed, 11 insertions(+), 9 deletions(-) > > > > > > diff --git a/argp/argp-parse.c b/argp/argp-parse.c > > > index a44b50f8e4..40a5896d21 100644 > > > --- a/argp/argp-parse.c > > > +++ b/argp/argp-parse.c > > > @@ -884,6 +884,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 +894,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. */ > > > -- > > > 2.39.2 > > > > > >