[email protected] (Carlos Martín Nieto) writes:
> How about something like this instead? We keep the access check and only
> do the stat call when we have found something we want to look at.
Sounds safer.
Looking at the way the stat call is indented twice, I suspect that
the variable can be defined inner scope, not at the top-level of the
function?
>
> ---8<---
>
> diff --git a/run-command.c b/run-command.c
> index 1101ef7..fb8a93c 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -85,6 +85,7 @@ static char *locate_in_PATH(const char *file)
> {
> const char *p = getenv("PATH");
> struct strbuf buf = STRBUF_INIT;
> + struct stat st;
>
> if (!p || !*p)
> return NULL;
> @@ -101,7 +102,8 @@ static char *locate_in_PATH(const char *file)
> }
> strbuf_addstr(&buf, file);
>
> - if (!access(buf.buf, F_OK))
> + if (!access(buf.buf, F_OK) &&
> + !stat(buf.buf, &st) && !S_ISDIR(st.st_mode))
> return strbuf_detach(&buf, NULL);
>
> if (!*end)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html