Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
Examples of errors detected by the V562…

Examples of errors detected by the V562 diagnostic

V562. Bool type value is compared with value of N. Consider inspecting the expression.


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();
  }
  ....
}

TheXTech

V562 It's odd to compare a bool type value with a value of 0. thextech editor.cpp 102


if(!MagicHand)
{
  if((getKeyState(vbKeyPageUp) == KEY_PRESSED) != 0)  // <=
  {
    if(ScrollRelease == true)
....

close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam