BUG OF THE MONTH | This code looks strange
V521 Such expressions using the ‘,’ operator are dangerous. Make sure the expression ‘m_to, m_from = it->first.getNumber()’ is correct. flipbook.cpp 509
class LoadImagesPopup final : public FileBrowserPopup { .... int m_from, m_to, ....; .... } void LoadImagesPopup::onFilePathClicked(....) { TLevel::Iterator it; .... it = level->begin(); m_to, m_from = it->first.getNumber(); for (; it != level->end(); ++it) m_to = it->first.getNumber(); if (m_from == -2 && m_to == -2) m_from = m_to = 1; m_minFrame = m_from; m_maxFrame = m_to; .... }
Perhaps the programmer expected that one could assign one value to several variables simply by writing them separated by commas. However, the “,” operator works differently in C ++. What happens is that the first operand is executed and the result is dropped, then the second operand is calculated. Even though the m_to variable is initialized in the subsequent loop, if something goes wrong and someone makes inaccurate refactoring, m_to might not get the value at all. Anyway, this code looks strange.
Please click here to see more bugs from this project.
I didn’t even know that is not a compiler error in C++!
LikeLike