Skip to content

Commit

Permalink
Fixed a bug limiting the extent of removeRange in ReferenceCountedArray
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoole committed Sep 21, 2018
1 parent 9fd0e53 commit bd211ce
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions modules/juce_core/containers/juce_Array.h
Expand Up @@ -871,10 +871,11 @@ class Array

auto endIndex = jlimit (0, values.size(), startIndex + numberToRemove);
startIndex = jlimit (0, values.size(), startIndex);
numberToRemove = endIndex - startIndex;

if (endIndex > startIndex)
if (numberToRemove > 0)
{
values.removeElements (startIndex, endIndex - startIndex);
values.removeElements (startIndex, numberToRemove);
minimiseStorageAfterRemoval();
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/juce_core/containers/juce_OwnedArray.h
Expand Up @@ -606,7 +606,7 @@ class OwnedArray
startIndex = jlimit (0, values.size(), startIndex);
numberToRemove = endIndex - startIndex;

if (endIndex > startIndex)
if (numberToRemove > 0)
{
if (deleteObjects)
{
Expand Down
7 changes: 4 additions & 3 deletions modules/juce_core/containers/juce_ReferenceCountedArray.h
Expand Up @@ -650,12 +650,13 @@ class ReferenceCountedArray
int numberToRemove)
{
const ScopedLockType lock (getLock());
auto start = jlimit (0, values.size(), startIndex);
startIndex = jlimit (0, values.size(), startIndex);
auto endIndex = jlimit (0, values.size(), startIndex + numberToRemove);
numberToRemove = endIndex - startIndex;

if (endIndex > start)
if (numberToRemove > 0)
{
for (int i = start; i < endIndex; ++i)
for (int i = startIndex; i < endIndex; ++i)
{
releaseObject (values[i]);
values[i] = nullptr; // (in case one of the destructors accesses this array and hits a dangling pointer)
Expand Down

0 comments on commit bd211ce

Please sign in to comment.