From acb1d1a668b2167b6761d751363cfadd258d87dc Mon Sep 17 00:00:00 2001 From: Matthew White <mehw.is.me@inventati.org> Date: Thu, 25 Aug 2016 15:26:18 +0200 Subject: [PATCH] Bugfix: Prevent sorting when there are less than two elements * src/utils.c (stable_sort): Add condition nmemb > 1, sort only when there is more than one element Prevent SIGSEGV. --- src/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.c b/src/utils.c index 9ab1b907..dcf90a6c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -2428,7 +2428,7 @@ void stable_sort (void *base, size_t nmemb, size_t size, int (*cmpfun) (const void *, const void *)) { - if (size > 1) + if (nmemb > 1 && size > 1) { void *temp = xmalloc (nmemb * size); mergesort_internal (base, temp, size, 0, nmemb - 1, cmpfun);