TetheringState and TetheringStateV2 each declare a NUMBER_OF_RESPONSE_FIELDS constant. Inside Parse, using namespace TetheringStateV2 brings the value 5 into scope, so the guarded block only runs when message.count() == 5, making at(0)..at(4) all in bounds. cppcheck instead resolves NUMBER_OF_RESPONSE_FIELDS to the unrelated TetheringState::NUMBER_OF_RESPONSE_FIELDS (value 2), so it treats the guard as 2 == message.count() and flags every access past index 1 as out of bounds.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What version of cppcheck did you use to create this bug? I tried to reproduce this using the current master branch and this issue you describe didn't happen, even with --library=qt
with --debug it looks like its working properly now:
containerOutOfBounds flags container accesses gated by a same-named constant from a different namespace, pulled in via using namespace
Minimal reproduction:
TetheringState and TetheringStateV2 each declare a NUMBER_OF_RESPONSE_FIELDS constant. Inside Parse, using namespace TetheringStateV2 brings the value 5 into scope, so the guarded block only runs when message.count() == 5, making at(0)..at(4) all in bounds. cppcheck instead resolves NUMBER_OF_RESPONSE_FIELDS to the unrelated TetheringState::NUMBER_OF_RESPONSE_FIELDS (value 2), so it treats the guard as 2 == message.count() and flags every access past index 1 as out of bounds.
What version of cppcheck did you use to create this bug? I tried to reproduce this using the current master branch and this issue you describe didn't happen, even with --library=qt
with --debug it looks like its working properly now:
using the first namespace
and using the second namespace
it might be related to#14859, and #14948