提交 68729696 编写于 作者: B Brandon Casey 提交者: Junio C Hamano

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: NBrandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 43d20a8c
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册