Browse Source

Avoided some UB warnings when trying to sort empty arrays

tags/2021-05-28
jules 8 years ago
parent
commit
c734e03dd0
1 changed files with 10 additions and 5 deletions
  1. +10
    -5
      modules/juce_core/containers/juce_ElementComparator.h

+ 10
- 5
modules/juce_core/containers/juce_ElementComparator.h View File

@@ -82,12 +82,17 @@ static void sortArray (ElementComparator& comparator,
int lastElement,
const bool retainOrderOfEquivalentItems)
{
SortFunctionConverter<ElementComparator> converter (comparator);
jassert (firstElement >= 0);
if (retainOrderOfEquivalentItems)
std::stable_sort (array + firstElement, array + lastElement + 1, converter);
else
std::sort (array + firstElement, array + lastElement + 1, converter);
if (lastElement > firstElement)
{
SortFunctionConverter<ElementComparator> converter (comparator);
if (retainOrderOfEquivalentItems)
std::stable_sort (array + firstElement, array + lastElement + 1, converter);
else
std::sort (array + firstElement, array + lastElement + 1, converter);
}
}


Loading…
Cancel
Save