From 9977f5c9b415ed300f1f4b4c8e787e8e4c6215f3 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 7 Jun 2012 10:21:43 -0400 Subject: [PATCH] Don't sort if there's nothing to do (prevents array underflow, too). (transplanted from 662a7e180c480ff7731493b688aee27e8e010887) --- physfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/physfs.c b/physfs.c index fcc82f6..27a555c 100644 --- a/physfs.c +++ b/physfs.c @@ -230,7 +230,8 @@ void __PHYSFS_sort(void *entries, PHYSFS_uint32 max, * Quicksort w/ Bubblesort fallback algorithm inspired by code from here: * http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html */ - __PHYSFS_quick_sort(entries, 0, max - 1, cmpfn, swapfn); + if (max > 0) + __PHYSFS_quick_sort(entries, 0, max - 1, cmpfn, swapfn); } /* __PHYSFS_sort */