tibirna / qgit

Official git repository for QGit.
Other
171 stars 66 forks source link

src/settingsimpl.cpp:108: suspicious for loop ? #146

Open dcb314 opened 2 months ago

dcb314 commented 2 months ago

C compiler clang says:

src/settingsimpl.cpp:108:5: warning: variable 'it' is incremented both in the loop header and in the loop body [-Wfor-loop-analysis]

Source code is

FOREACH_SL(it, _uInfo) {
    comboBoxUserSrc->addItem(*it);
    ++it;
    if (!found && !(*it).isEmpty())
        found = true;
    if (!found)
        idx++;
    ++it;
}

Suggest code rework.

tibirna commented 2 months ago

Thank you for the investigation. The loop is correct. That code handles a bytestream list of 9 items, in 3 groups of 3, in which decision on the first element in the triad is taken based on information from the second. The code can't be easily made more readable. If you like you can add a #pragma GCC to disable the warning. Patches are greatly appreciated.