[PATCH 2/3] refs.c: abort ref search if ref array is empty
- From
Brandon Casey <casey@nrlssc.navy.mil>
- Date
- Oct 8, 2011, 03:20 UTC
- Message-ID
- <5WORKOGzj9pUA6-WazYHWimMbFMh2dFdPh-tzgQwRKUjBmg5avzikX-E8YCuF6-WDVQwYJe92QfzjJryO0gSItzZkhfefVSSSpOvoOUGB9HVM7KEfTIWsriW5ZyQAa1YxwTYeujykWQ@cipher.nrlssc.navy.mil>
- In-Reply-To
- <3k7giKa3PkJZo51iAXivXCFEZpYY2WC3depjtuvksrCQPax7dSLVCXpMlqLxWtZfSp6P10yMhMg@cipher.nrlssc.navy.mil>
From: Brandon Casey <drafnel@gmail.com>
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> --- refs.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/refs.c b/refs.c index c31b461..cbc4c5d 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);
-- 1.7.7