Skip to content

Commit

Permalink
get_tree_entry(): do not call find_tree_entry() on an empty tree
Browse files Browse the repository at this point in the history
We know we will find nothing.

This incidentally squelches false warning from gcc about potentially
uninitialized usage of t.entry fields. For an empty tree, it is true that
init_tree_desc() does not call decode_tree_entry() and the tree_desc is
left uninitialized, but find_tree_entry() only calls tree_entry_extract()
that uses the tree_desc while it has more things to read from the tree, so
the uninitialized t.entry fields are never used in such a case anyway.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Oct 27, 2011
1 parent 0de1633 commit 5fb8c05
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tree-walk.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch
int retval;
void *tree;
unsigned long size;
struct tree_desc t;
unsigned char root[20];

tree = read_object_with_reference(tree_sha1, tree_type, &size, root);
Expand All @@ -478,8 +477,13 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch
return 0;
}

init_tree_desc(&t, tree, size);
retval = find_tree_entry(&t, name, sha1, mode);
if (!size) {
retval = -1;
} else {
struct tree_desc t;
init_tree_desc(&t, tree, size);
retval = find_tree_entry(&t, name, sha1, mode);
}
free(tree);
return retval;
}
Expand Down

0 comments on commit 5fb8c05

Please sign in to comment.