File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -633,7 +633,21 @@ class LegacyVoteCounterContext
633633 const LegacyChoiceMap& GetChoices ()
634634 {
635635 if (m_legacy_choices_cache.empty ()) {
636- for (uint8_t i = 0 ; i < m_poll.Choices ().size (); ++i) {
636+ uint8_t m_poll_choices_size = 0 ;
637+
638+ // This silences the code scan warning of a possible infinite loop due to the overflow of the uint8_t i counter
639+ // against the comparison to m_poll.Choices.size(). Note it is the logged equivalent to std::min<uint8_t>. Since
640+ // this is legacy polls only and those are no longer issued, and this condition does not actually exist in the
641+ // chain, this is purely for formality's sake.
642+ if (m_poll.Choices ().size () > (size_t ) std::numeric_limits<uint8_t >::max ()) {
643+ LogPrintf (" WARN: %s: Number of legacy poll choices exceeds bins available in m_legacy_choices_cache map. "
644+ " Limiting to %u." , __func__, std::numeric_limits<uint8_t >::max ());
645+ m_poll_choices_size = std::numeric_limits<uint8_t >::max ();
646+ } else {
647+ m_poll_choices_size = m_poll.Choices ().size ();
648+ }
649+
650+ for (uint8_t i = 0 ; i < m_poll_choices_size; ++i) {
637651 std::string label = m_poll.Choices ().At (i)->m_label ;
638652 label = ToLower (label);
639653
You can’t perform that action at this time.
0 commit comments