summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0de1633)
raw | patch | inline | side by side (parent: 0de1633)
author | Junio C Hamano <gitster@pobox.com> | |
Thu, 27 Oct 2011 18:18:40 +0000 (11:18 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 27 Oct 2011 18:24:01 +0000 (11:24 -0700) |
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>
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>
tree-walk.c | patch | blob | history |
diff --git a/tree-walk.c b/tree-walk.c
index f5d19f9cc16ec1c94c9b1bf8d14fd3d8620ff871..cc2f14a0d6fd3a115ab453b4f28823400550cf60 100644 (file)
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -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);
@@ -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;
}