Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/gridcoin/voting/result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,21 @@ class LegacyVoteCounterContext
const LegacyChoiceMap& GetChoices()
{
if (m_legacy_choices_cache.empty()) {
for (uint8_t i = 0; i < m_poll.Choices().size(); ++i) {
uint8_t m_poll_choices_size = 0;

// This silences the code scan warning of a possible infinite loop due to the overflow of the uint8_t i counter
// against the comparison to m_poll.Choices.size(). Note it is the logged equivalent to std::min<uint8_t>. Since
// this is legacy polls only and those are no longer issued, and this condition does not actually exist in the
// chain, this is purely for formality's sake.
if (m_poll.Choices().size() > (size_t) std::numeric_limits<uint8_t>::max()) {
LogPrintf("WARN: %s: Number of legacy poll choices exceeds bins available in m_legacy_choices_cache map. "
"Limiting to %u.", __func__, std::numeric_limits<uint8_t>::max());
m_poll_choices_size = std::numeric_limits<uint8_t>::max();
} else {
m_poll_choices_size = m_poll.Choices().size();
}

for (uint8_t i = 0; i < m_poll_choices_size; ++i) {
std::string label = m_poll.Choices().At(i)->m_label;
label = ToLower(label);

Expand Down