From 03f8528315fa46c95991a34f3325d7b33ae5538c Mon Sep 17 00:00:00 2001
From: Edward Rudd <urkle@outoforder.cc>
Date: Sat, 02 May 2020 21:48:36 +0000
Subject: [PATCH] Update source to SDL2 2.0.12

---
 source/src/stdlib/SDL_qsort.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/source/src/stdlib/SDL_qsort.c b/source/src/stdlib/SDL_qsort.c
index 700b9da..060db21 100644
--- a/source/src/stdlib/SDL_qsort.c
+++ b/source/src/stdlib/SDL_qsort.c
@@ -1,6 +1,6 @@
 /*
   Simple DirectMedia Layer
-  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
@@ -64,7 +64,7 @@
 
 /*
 This code came from Gareth McCaughan, under the zlib license.
-Specifically this: https://www.mccaughan.org.uk/software/qsort.c-1.14
+Specifically this: https://www.mccaughan.org.uk/software/qsort.c-1.15
 
 Everything below this comment until the HAVE_QSORT #endif was from Gareth
 (any minor changes will be noted inline).
@@ -143,6 +143,10 @@
  *   2016-02-21 v1.14 Replace licence with 2-clause BSD,
  *                    and clarify a couple of things in
  *                    comments. No code changes.
+ *   2016-03-10 v1.15 Fix bug kindly reported by Ryan Gordon
+ *                    (pre-insertion-sort messed up).
+ *                    Disable DEBUG_QSORT by default.
+ *                    Tweak comments very slightly.
  */
 
 /* BEGIN SDL CHANGE ... commented this out with an #if 0 block. --ryan. */
@@ -151,9 +155,9 @@
 #include <stdlib.h>
 #include <string.h>
 
-#define DEBUG_QSORT
+#undef DEBUG_QSORT
 
-static char _ID[]="<qsort.c gjm 1.14 2016-02-21>";
+static char _ID[]="<qsort.c gjm 1.15 2016-03-10>";
 #endif
 /* END SDL CHANGE ... commented this out with an #if 0 block. --ryan. */
 
@@ -316,7 +320,9 @@
  * We find the smallest element from the first |nmemb|,
  * or the first |limit|, whichever is smaller;
  * therefore we must have ensured that the globally smallest
- * element is in the first |limit|.
+ * element is in the first |limit| (because our
+ * quicksort recursion bottoms out only once we
+ * reach subarrays smaller than |limit|).
  */
 #define PreInsertion(swapper,limit,sz)		\
   first=base;					\
@@ -499,7 +505,7 @@
       Recurse(TRUNC_words)
     }
   }
-  PreInsertion(SWAP_words,(TRUNC_words/WORD_BYTES),WORD_BYTES);
+  PreInsertion(SWAP_words,TRUNC_words/WORD_BYTES,WORD_BYTES);
   /* Now do insertion sort. */
   last=((char*)base)+nmemb*WORD_BYTES;
   for (first=((char*)base)+WORD_BYTES;first!=last;first+=WORD_BYTES) {
@@ -526,7 +532,6 @@
   else
     qsort_words(base,nmemb,compare);
 }
-
 
 #endif /* HAVE_QSORT */
 

--
Gitblit v1.9.3