1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-11 03:26:12 +02:00

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 <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Brandon Casey 2011-10-07 22:20:21 -05:00 committed by Junio C Hamano
parent 43d20a8c50
commit 687296960d

3
refs.c
View File

@ -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);