summaryrefslogtreecommitdiff
path: root/pack-refs.c
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2013-03-17 04:22:36 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-03-17 12:49:03 -0700
commit75a95490474ab6e991cbbbd10d980498a9109648 (patch)
tree5acd800ccaad1c37aff8049fe4fb808314cbdaca /pack-refs.c
parentGit 1.7.12.4 (diff)
downloadtgif-75a95490474ab6e991cbbbd10d980498a9109648.tar.xz
avoid segfaults on parse_object failure
Many call-sites of parse_object assume that they will get a non-NULL return value; this is not the case if we encounter an error while parsing the object. This patch adds a wrapper function around parse_object that handles dying automatically, and uses it anywhere we immediately try to access the return value as a non-NULL pointer (i.e., anywhere that we would currently segfault). This wrapper may also be useful in other places. The most obvious one is code like: o = parse_object(sha1); if (!o) die(...); However, these should not be mechanically converted to parse_object_or_die, as the die message is sometimes customized. Later patches can address these sites on a case-by-case basis. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-refs.c')
-rw-r--r--pack-refs.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/pack-refs.c b/pack-refs.c
index f09a054228..6a689f35cb 100644
--- a/pack-refs.c
+++ b/pack-refs.c
@@ -40,7 +40,7 @@ static int handle_one_ref(const char *path, const unsigned char *sha1,
fprintf(cb->refs_file, "%s %s\n", sha1_to_hex(sha1), path);
if (is_tag_ref) {
- struct object *o = parse_object(sha1);
+ struct object *o = parse_object_or_die(sha1, path);
if (o->type == OBJ_TAG) {
o = deref_tag(o, path, 0);
if (o)