Skip to content

Commit

Permalink
Fixed playListIndex's type and potential overflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpintroniK committed Aug 5, 2019
1 parent 2c5a1cb commit b70ed24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Sound/Mixer/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ namespace Sound
{
// Add sound to playList
//playList.emplace_back(id, volume, true);
const auto index = playListIndex.fetch_add(1, std::memory_order_relaxed); // FIXME: protect from overflow
const auto index = playListIndex.fetch_add(1, std::memory_order_relaxed);

// Protect from overflow (ignore new sound...)
if(index >= playList.size())
{
return;
}

playList[index].id = id;
playList[index].volume = volume;
playList[index].isPlaying.store(true, std::memory_order_release);
Expand Down
2 changes: 1 addition & 1 deletion Sound/Mixer/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Sound

std::shared_ptr<SoundBank> soundBank;
std::array<SoundState, 256> playList;
std::atomic<int> playListIndex{0};
std::atomic<size_t> playListIndex{0};

};

Expand Down

0 comments on commit b70ed24

Please sign in to comment.