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


V562. It's odd to compare a bool type value with a value of N.


Spvolren

V562 It's odd to compare a bool type value with a value of -1: !(fp = fopen (filename, "wb")) == - 1. spvolren ppm.c 118


void ppmWrite(char *filename, PPMFile *ppmFile)
{
  ....
  FILE *fp;
  if (! (fp = fopen(filename, "wb")) == -1) {
    perror("opening image file failed");
    exit(1);
  }
  ....
}

ReactOS

V562 It's odd to compare 0 or 1 with a value of 4294967295. eventlog file.c 264


#define INVALID_SET_FILE_POINTER ((DWORD)-1)

BOOL LogfInitializeExisting(PLOGFILE LogFile)
{
  ....
  if (!SetFilePointer(LogFile->hFile, 0, NULL, FILE_BEGIN) ==
      INVALID_SET_FILE_POINTER)
  {
      DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
      return FALSE;
  }
  ....
}

This is what should have been written here: if (SetFilePointer(LogFile->hFile, 0, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER)


Blender

V562 It's odd to compare 0 or 1 with a value of 1: (base->object->actcol > 0) > (1). bf_editor_render render_preview.c 361


#define MAX2(x,y) ( (x)>(y) ? (x) : (y) )

static Scene *preview_prepare_scene(....)
{
  ....
  int actcol = MAX2(base->object->actcol > 0, 1) - 1;
  ....
}

Most likely this is what should be written here: int actcol = MAX2(base->object->actcol, 1) - 1;


Windows 8 Driver Samples

V562 It's odd to compare 0 or 1 with a value of 5: 0 < dwMaskSize < 5. nic_pm.c 825


VOID MPCreateProgrammableFilter(....)
{
  ....
  ASSERT (0 < dwMaskSize <5);
  ....
}

Haiku Operation System

V562 It's odd to compare 0 or 1 with a value of 0. cmp.c 300


#ifndef same_file
# define same_file(s, t) \
    ((((s)->st_ino == (t)->st_ino) \
     && ((s)->st_dev == (t)->st_dev)) \
     || same_special_file (s, t))
#endif

int
main (int argc, char **argv)
{
  ....
  if (0 < same_file (&stat_buf[0], &stat_buf[1])           // <=
      && same_file_attributes (&stat_buf[0], &stat_buf[1])
      && file_position (0) == file_position (1))
    return EXIT_SUCCESS;
  ....
}

Similar errors can be found in some other places:

  • V562 It's odd to compare 0 or 1 with a value of 0. cmp.c 313

NCBI Genome Workbench

V562 It's odd to compare a bool type value with a value of 0: (((status) & 0x7f) == 0) != 0. ncbi_process.cpp 111


bool CProcess::CExitInfo::IsExited(void) const
{
    EXIT_INFO_CHECK;
    if (state != eExitInfo_Terminated) {
        return false;
    }
#if   defined(NCBI_OS_UNIX)
    return WIFEXITED(status) != 0;
#elif defined(NCBI_OS_MSWIN)
    // The process always terminates with exit code
    return true;
#endif
}
return (((status) & 0x7f) == 0) != 0;

return (((status) & 0x7f) == 0) != 0;

Similar errors can be found in some other places:

  • V562 It's odd to compare a bool type value with a value of 0. ncbi_process.cpp 126

Haiku Operation System

V562 It's odd to compare a bool type value with a value of 18: 0x12 == IsProfessionalSpdif(). CEchoGals_mixer.cpp 533


typedef bool BOOL;

virtual BOOL IsProfessionalSpdif() { ... }

#define ECHOSTATUS_DSP_DEAD 0x12

ECHOSTATUS CEchoGals::ProcessMixerFunction(....)
{
  ....
  if ( ECHOSTATUS_DSP_DEAD == IsProfessionalSpdif() ) // <=
  {
    Status = ECHOSTATUS_DSP_DEAD;
  }
  else
  {
    pMixerFunction->Data.bProfSpdif = IsProfessionalSpdif();
  }
  ....
}


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

Проверено проектов
361
Собрано ошибок
13 417

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

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

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

goto PVS-Studio;