Skip to content

Commit 6872969

Browse files
drafnelgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 43d20a8 commit 6872969

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

refs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ static struct ref_entry *search_ref_array(struct ref_array *array, const char *n
110110
if (name == NULL)
111111
return NULL;
112112

113+
if (!array->nr)
114+
return NULL;
115+
113116
len = strlen(name) + 1;
114117
e = xmalloc(sizeof(struct ref_entry) + len);
115118
memcpy(e->name, name, len);

0 commit comments

Comments
 (0)