Skip to content

Commit

Permalink
refs.c: abort ref search if ref array is empty
Browse files Browse the repository at this point in the history
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 <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Brandon Casey authored and Junio C Hamano committed Oct 10, 2011
1 parent 43d20a8 commit 6872969
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6872969

Please sign in to comment.