From: Brandon Casey Date: Sat, 8 Oct 2011 03:20:21 +0000 (-0500) Subject: refs.c: abort ref search if ref array is empty X-Git-Tag: v1.7.8-rc0~106^2~1 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=687296960d774a45df31df7bc371d01106a6f6b7;p=git.git refs.c: abort ref search if ref array is empty The bsearch() implementation on IRIX 6.5 segfaults if it is passed NULL for the base array argument even if number-of-elements is zero. So, let's work around it by detecting an empty array and aborting early. This is a useful optimization in its own right anyway, since we avoid a useless allocation and initialization of the ref_entry when the ref array is empty. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- diff --git a/refs.c b/refs.c index c31b46166..cbc4c5d28 100644 --- a/refs.c +++ b/refs.c @@ -110,6 +110,9 @@ static struct ref_entry *search_ref_array(struct ref_array *array, const char *n if (name == NULL) return NULL; + if (!array->nr) + return NULL; + len = strlen(name) + 1; e = xmalloc(sizeof(struct ref_entry) + len); memcpy(e->name, name, len);