Commit 71094b4e authored by Stewart Brodie's avatar Stewart Brodie
Browse files

Fix for qsort to stop aborts.

Detail:
  If qsort is passed an invalid base pointer and the number of entries
    is zero, then due to some pointer artihmetic going wrong, it aborts.
    The fix is to trap zero length arrays and exit quickly.
Admin:
  Required by cmhg prior to version 5.20 which had an explicit fix to
    prevent triggering this bug.
  Reportedly this fix is required by PhotoDesk prior to version 3.03.

Version 4.96. Tagged as 'RISC_OSLib-4_96'
parent 0c27e5e4
......@@ -6,9 +6,9 @@
GBLS Module_MinorVersion
GBLS Module_Date
GBLS Module_FullVersion
Module_MajorVersion SETS "4.95"
Module_Version SETA 495
Module_MajorVersion SETS "4.96"
Module_Version SETA 496
Module_MinorVersion SETS ""
Module_Date SETS "09 Jul 1999"
Module_FullVersion SETS "4.95"
Module_Date SETS "21 Sep 1999"
Module_FullVersion SETS "4.96"
END
/* (4.95)
/* (4.96)
*
* This file is automatically maintained by srccommit, do not edit manually.
*
*/
#define Module_MajorVersion_CMHG 4.95
#define Module_MajorVersion_CMHG 4.96
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 09 Jul 1999
#define Module_Date_CMHG 21 Sep 1999
#define Module_MajorVersion "4.95"
#define Module_Version 495
#define Module_MajorVersion "4.96"
#define Module_Version 496
#define Module_MinorVersion ""
#define Module_Date "09 Jul 1999"
#define Module_Date "21 Sep 1999"
#define Module_FullVersion "4.95"
#define Module_FullVersion "4.96"
......@@ -206,7 +206,10 @@ void qsort(void *base, size_t nmemb, size_t size,
/* This uses a quicksort method, but one that is arranged to complete in */
/* about n*log(n) steps for sorted and inverse sorted inputs. */
char *b, *endp;
if (size == 0) return;
/* SNB 990921: The nmemb == 0 fast exit test was added because if the */
/* caller passed nmemb as 0 and base as a null pointer, the pointer */
/* arithmetic goes bang. */
if (size == 0 || nmemb == 0) return;
if (nmemb > SUBDIVISION_LIMIT)
partition_sort(base, nmemb, size, compar);
/* Now I do an insertion sort on the array that is left over. This makes */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment