[3/6] posix: Use malloc instead of alloca for the glob user name
Checks
| Context |
Check |
Description |
| redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
| linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Test passed
|
Commit Message
Use malloc unconditionally. The name is only needed for the passwd
lookup that follows, which is far more expensive than the allocation.
Checked on x86_64-linux-gnu, aarch64-linux-gnu, and i686-linux-gnu.
---
posix/glob.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
Comments
Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> Use malloc unconditionally. The name is only needed for the passwd
> lookup that follows, which is far more expensive than the allocation.
>
> Checked on x86_64-linux-gnu, aarch64-linux-gnu, and i686-linux-gnu.
> ---
> posix/glob.c | 16 +++++-----------
> 1 file changed, 5 insertions(+), 11 deletions(-)
Looks good.
It annoys me slightly that we use "int" instead of "bool" there, but
that is separate from your patches. :)
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
Collin
@@ -826,19 +826,13 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
user_name = dirname + 1;
else
{
- char *newp;
- if (glob_use_alloca (alloca_used, end_name - dirname))
- newp = alloca_account (end_name - dirname, alloca_used);
- else
+ char *newp = malloc (end_name - dirname);
+ if (newp == NULL)
{
- newp = malloc (end_name - dirname);
- if (newp == NULL)
- {
- retval = GLOB_NOSPACE;
- goto out;
- }
- malloc_user_name = 1;
+ retval = GLOB_NOSPACE;
+ goto out;
}
+ malloc_user_name = 1;
if (unescape != NULL)
{
char *p = mempcpy (newp, dirname + 1,