mirror of
https://git.zx2c4.com/cgit
synced 2024-11-10 18:48:43 +00:00
ui-tree: remove a fixed size buffer
As libgit.a moves away from using fixed size buffers, there is no guarantee that PATH_MAX is sufficient for all of the paths in a Git tree, so we should use a dynamically sized buffer here. Coverity-Id: 141884 Signed-off-by: John Keeping <john@keeping.me.uk>
This commit is contained in:
parent
f80b73fa20
commit
e18a85b6a2
15
ui-tree.c
15
ui-tree.c
@ -324,22 +324,25 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base,
|
|||||||
const char *pathname, unsigned mode, int stage, void *cbdata)
|
const char *pathname, unsigned mode, int stage, void *cbdata)
|
||||||
{
|
{
|
||||||
struct walk_tree_context *walk_tree_ctx = cbdata;
|
struct walk_tree_context *walk_tree_ctx = cbdata;
|
||||||
static char buffer[PATH_MAX];
|
|
||||||
|
|
||||||
if (walk_tree_ctx->state == 0) {
|
if (walk_tree_ctx->state == 0) {
|
||||||
memcpy(buffer, base->buf, base->len);
|
struct strbuf buffer = STRBUF_INIT;
|
||||||
strcpy(buffer + base->len, pathname);
|
|
||||||
if (strcmp(walk_tree_ctx->match_path, buffer))
|
strbuf_addbuf(&buffer, base);
|
||||||
|
strbuf_addstr(&buffer, pathname);
|
||||||
|
if (strcmp(walk_tree_ctx->match_path, buffer.buf))
|
||||||
return READ_TREE_RECURSIVE;
|
return READ_TREE_RECURSIVE;
|
||||||
|
|
||||||
if (S_ISDIR(mode)) {
|
if (S_ISDIR(mode)) {
|
||||||
walk_tree_ctx->state = 1;
|
walk_tree_ctx->state = 1;
|
||||||
set_title_from_path(buffer);
|
set_title_from_path(buffer.buf);
|
||||||
|
strbuf_release(&buffer);
|
||||||
ls_head();
|
ls_head();
|
||||||
return READ_TREE_RECURSIVE;
|
return READ_TREE_RECURSIVE;
|
||||||
} else {
|
} else {
|
||||||
walk_tree_ctx->state = 2;
|
walk_tree_ctx->state = 2;
|
||||||
print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev);
|
print_object(sha1, buffer.buf, pathname, walk_tree_ctx->curr_rev);
|
||||||
|
strbuf_release(&buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user