Skip to content

Commit

Permalink
Fix uninitialized reference counts in Component
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusTomlinson committed Oct 29, 2023
1 parent 31b73f3 commit 4852c99
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ class Component
std::vector<DSPatch::SignalBus> inputBuses;
std::vector<DSPatch::SignalBus> outputBuses;

std::vector<std::vector<std::pair<int, int>>> refs; // ref_total:ref_counter per output, per buffer
struct RefCounter final
{
int count = 0;
int total = 0;
};

std::vector<std::vector<RefCounter>> refs; // RefCounter per output, per buffer

std::vector<Wire> inputWires;

Expand Down Expand Up @@ -368,36 +374,36 @@ void internal::Component::GetOutput( int bufferNo, int fromOutput, int toInput,

auto& ref = refs[bufferNo][fromOutput];

if ( ref.first == 1 )
if ( ref.total == 1 )
{
// there's only one reference, move the signal immediately
toBus.MoveSignal( toInput, signal );
return;
}
else if ( ++ref.second != ref.first )
else if ( ++ref.count != ref.total )
{
// this is not the final reference, copy the signal
toBus.SetSignal( toInput, signal );
return;
}

// this is the final reference, reset the counter, move the signal
ref.second = 0;
ref.count = 0;
toBus.MoveSignal( toInput, signal );
}

void internal::Component::IncRefs( int output )
{
for ( auto& ref : refs )
{
++ref[output].first;
++ref[output].total;
}
}

void internal::Component::DecRefs( int output )
{
for ( auto& ref : refs )
{
--ref[output].first;
--ref[output].total;
}
}

0 comments on commit 4852c99

Please sign in to comment.