summaryrefslogtreecommitdiff
path: root/builtin/update-index.c
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2015-05-04 19:11:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-05-05 17:31:51 (GMT)
commitd7a643b73ff4d54e2ad746e3a65a50bf21ac71ce (patch)
treea282c59b258def30ab826b5559899ea02c335fd5 /builtin/update-index.c
parent3d4a3ffe64162b45ae7c991fc60623ecb4678cfd (diff)
downloadgit-d7a643b73ff4d54e2ad746e3a65a50bf21ac71ce.zip
git-d7a643b73ff4d54e2ad746e3a65a50bf21ac71ce.tar.gz
git-d7a643b73ff4d54e2ad746e3a65a50bf21ac71ce.tar.bz2
prefix_path(): unconditionally free results in the callers
As of d089ebaa (setup: sanitize absolute and funny paths in get_pathspec(), 2008-01-28), prefix_path() always returns a newly allocated string, so callers should free its result. Additionally, drop the const from variables to which the result of the prefix_path() is assigned, so they can be free()'d without having to cast-away the constness. Signed-off-by: Stefan Beller <sbeller@google.com> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/update-index.c')
-rw-r--r--builtin/update-index.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 6271b54..0665b31 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -532,10 +532,9 @@ static int do_unresolve(int ac, const char **av,
for (i = 1; i < ac; i++) {
const char *arg = av[i];
- const char *p = prefix_path(prefix, prefix_length, arg);
+ char *p = prefix_path(prefix, prefix_length, arg);
err |= unresolve_one(p);
- if (p < arg || p > arg + strlen(arg))
- free((char *)p);
+ free(p);
}
return err;
}
@@ -871,14 +870,14 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
case PARSE_OPT_DONE:
{
const char *path = ctx.argv[0];
- const char *p;
+ char *p;
setup_work_tree();
p = prefix_path(prefix, prefix_length, path);
update_one(p);
if (set_executable_bit)
chmod_path(set_executable_bit, p);
- free((char *)p);
+ free(p);
ctx.argc--;
ctx.argv++;
break;
@@ -909,7 +908,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
setup_work_tree();
while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
- const char *p;
+ char *p;
if (line_termination && buf.buf[0] == '"') {
strbuf_reset(&nbuf);
if (unquote_c_style(&nbuf, buf.buf, NULL))
@@ -920,7 +919,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
update_one(p);
if (set_executable_bit)
chmod_path(set_executable_bit, p);
- free((char *)p);
+ free(p);
}
strbuf_release(&nbuf);
strbuf_release(&buf);