Примеры ошибок, обнаруженных с помощью диагностики V516


V516. Consider inspecting an odd expression. Non-null function pointer is compared to null.


Audacity

V516 Consider inspecting an odd expression. Non-null function pointer is compared to null: 'sf_error != 0'. libsndfile sndfile.c 491


int sf_error (SNDFILE *sndfile)
{
  ....
  if (! sndfile)
  {
    if (sf_error != 0)
      return sf_errno ;
    return 0 ;
  } ;
  ....
}

Strange code. Perhaps there should be (sf_errno != 0). But why not simply write "return sf_errno;" then?


Micro-Manager

V516 Consider inspecting an odd expression. Non-null function pointer is compared to null: 'MP285::GetMotionMode == 0'. MP285ZStage.cpp 558


class MP285
{
  ....
  static int  GetMotionMode() { return m_nMotionMode; }
  ....
};

int ZStage::_SetPositionSteps(....)
{
  ....
  if (MP285::GetMotionMode == 0)
  {
    long lOldZPosSteps = (long)MP285::Instance()->GetPositionZ();
    dSec = (double)labs(lZPosSteps-lOldZPosSteps) / dVelocity;
  }
  else
  {
     dSec = (double)labs(lZPosSteps) / dVelocity;
  }
  ....
}

This is what should have been written here: if (MP285::GetMotionMode() == 0)



Найденные ошибки

Проверено проектов
366
Собрано ошибок
13 539

А ты совершаешь ошибки в коде?

Проверь с помощью
PVS-Studio

Статический анализ
кода для C, C++, C#
и Java

goto PVS-Studio;