diff options
author | Jeff King <peff@peff.net> | 2015-08-10 05:37:45 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-08-10 15:37:13 -0700 |
commit | 03f2c7731b59de75357730bc511ffa8847e1fb81 (patch) | |
tree | dc1ffb12f1ab50f46c811b73402ce5beca71c45b /run-command.c | |
parent | 470e28d4e16dd994cd985914377fa8ccb5f86227 (diff) | |
download | git-03f2c7731b59de75357730bc511ffa8847e1fb81.tar.gz |
find_hook: keep our own static buffer
The find_hook function returns the results of git_path,
which is a static buffer shared by other path-related calls.
Returning such a buffer is slightly dangerous, because it
can be overwritten by seemingly unrelated functions.
Let's at least keep our _own_ static buffer, so you can
only get in trouble by calling find_hook in quick
succession, which is less likely to happen and more obvious
to notice.
While we're at it, let's add some documentation of the
function's limitations.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'run-command.c')
-rw-r--r-- | run-command.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/run-command.c b/run-command.c index 4d73e90fad..28e1d55cb9 100644 --- a/run-command.c +++ b/run-command.c @@ -797,11 +797,13 @@ int finish_async(struct async *async) const char *find_hook(const char *name) { - const char *path = git_path("hooks/%s", name); - if (access(path, X_OK) < 0) - path = NULL; + static struct strbuf path = STRBUF_INIT; - return path; + strbuf_reset(&path); + strbuf_git_path(&path, "hooks/%s", name); + if (access(path.buf, X_OK) < 0) + return NULL; + return path.buf; } int run_hook_ve(const char *const *env, const char *name, va_list args) |