]> git.ipfire.org Git - thirdparty/git.git/commit - object.h
avoid segfaults on parse_object failure
authorJeff King <peff@peff.net>
Sun, 17 Mar 2013 08:22:36 +0000 (04:22 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sun, 17 Mar 2013 19:49:03 +0000 (12:49 -0700)
commit75a95490474ab6e991cbbbd10d980498a9109648
tree5acd800ccaad1c37aff8049fe4fb808314cbdaca
parent7e2010537e96d0a1144520222f20ba1dc3d61441
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>
bundle.c
object.c
object.h
pack-refs.c