This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/3] posix: Remove dynamic memory allocation from execl{e,p}
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>, libc-alpha at sourceware dot org
- Date: Fri, 26 Feb 2016 10:47:47 -0800
- Subject: Re: [PATCH 1/3] posix: Remove dynamic memory allocation from execl{e,p}
- Authentication-results: sourceware.org; auth=none
- References: <1456495001-5298-1-git-send-email-adhemerval dot zanella at linaro dot org> <1456495001-5298-2-git-send-email-adhemerval dot zanella at linaro dot org>
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.
+ 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.
+ 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.
+ continue;
}
That 'continue;' is redundant and should be removed.