From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 36589 invoked by alias); 26 Feb 2016 19:40:50 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 36489 invoked by uid 89); 26 Feb 2016 19:40:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=HTo:U*eggert X-HELO: mail-yw0-f180.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=s/CP+kD+FtlWwVZXkoMfuQG46bBZBfCom5A2yD/zCW4=; b=O2OxoMRktRt0gNpG36bOeAf+vyE+GuT1+nA6+GGZfP0/AY4qPZ0HndYJBzGrF4wRu1 rnjlPEog1wsMxNJ8I2qQICL6FcDUNllD7Bk1l7lx9ICwkWp+rHlZZIQTiJ7+VZRM8s0G hdqEarrGAbQHSNUxIncNYI4ztz8RFM0AETEFyKCeRROQzPJCspjwHBURptfVPzhxSdRY g2WZSkW4PmadkeS3qOg6RpxE+hZoCJ13VpVEpEOX2i22KFvNRnMl9OKCJmXuIA63w8RV jGppF+4x+Ze10VZH2F5uOSp6evzRDRo9ofwCjVrkY0WE1Drhd3A5FHEeEtzo64MkWfBY QAdQ== X-Gm-Message-State: AD7BkJK38GJmGEt+BhG5Y3sREflD9lif6SzveM7t8PcVGb3XTSMCY8Jc5xI7IOXiBM9AdfUK X-Received: by 10.129.73.207 with SMTP id w198mr1946427ywa.223.1456515645414; Fri, 26 Feb 2016 11:40:45 -0800 (PST) Subject: Re: [PATCH 1/3] posix: Remove dynamic memory allocation from execl{e,p} To: Paul Eggert , libc-alpha@sourceware.org References: <1456495001-5298-1-git-send-email-adhemerval.zanella@linaro.org> <1456495001-5298-2-git-send-email-adhemerval.zanella@linaro.org> <56D09DD3.2050601@cs.ucla.edu> From: Adhemerval Zanella Message-ID: <56D0AA3A.9020207@linaro.org> Date: Fri, 26 Feb 2016 19:44:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <56D09DD3.2050601@cs.ucla.edu> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-02/txt/msg00845.txt.bz2 On 26-02-2016 15:47, Paul Eggert wrote: > On 02/26/2016 05:56 AM, Adhemerval Zanella wrote: >> + for (i = 1; i < argc; i++) >> + argv[i] = va_arg (ap, char *); >> + argv[i] = NULL; > > Change "i < argc" to "i <= argc" and remove the "argv[i] = NULL;", as that's a bit simpler and faster. I added to make it explicit, I will change that. > >> + int i; >> + char *argv[argc + 1]; >> + char **envp; >> + va_start (ap, arg); >> + argv[0] = (char *) arg; >> + for (i = 1; i <= argc; i++) > > This sort of thing has undefined behavior on x86-64 if argc == INT_MAX. You can fix this by changing the type of argc and of i from int to ptrdiff_t. > Indeed, but afaik this code won't execute if argc == INT_MAX (the argument sanity check will make the function with E2BIG). >> + if (argc == INT_MAX) >> { >> + errno = E2BIG; >> + return -1; >> } > > Doesn't that have undefined behavior? My impression from C11 is that since the function has called va_start it must call va_end before returning. > Yes, I will remove it. >> + continue; >> } > > That 'continue;' is redundant and should be removed. I will remove it.