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.

One thought on “OpenToonz

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.