diff --git a/CHANGELOG.md b/CHANGELOG.md index e3edab4..a646e92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ are not even initialized to a default value. specific circumstances. - Added `JsonMerge()` to the JSON API to merge two JSON objects together. - Make `HttpRouter` decode path parts before matching them on regular expressions. +- Fixed a bug in `ArraySort()` that would crash programs if the passed array has no + elements. ## v0.4.0 @@ -30,4 +32,4 @@ project with its own independent releases. This allows it to develop at a much m rapid pace than Telodendria. Changes in future releases will be reported here. Since this is the first release, -there are no changes to show. \ No newline at end of file +there are no changes to show. diff --git a/src/Array.c b/src/Array.c index c2af556..a289431 100644 --- a/src/Array.c +++ b/src/Array.c @@ -267,8 +267,9 @@ ArrayQuickSort(Array * array, size_t low, size_t high, int (*compare) (void *, v void ArraySort(Array * array, int (*compare) (void *, void *)) { - if (!array) + if (!ArraySize(array)) { + // If a NULL ptr was given, or the array has no elements, do nothing. return; } ArrayQuickSort(array, 0, array->size - 1, compare);