Examples of errors detected by the V581 diagnostic

V581. The conditional expressions of the 'if' operators situated alongside each other are identical.


MongoDB

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 44, 46. parallel.h 46


string _server;

bool operator<( const ServerAndQuery& other ) const {
  if ( ! _orderObject.isEmpty() )
    return _orderObject.woCompare( other._orderObject ) < 0;

  if ( _server < other._server )
    return true;
  if ( other._server > _server )
    return false;
  return _extra.woCompare( other._extra ) < 0;
}

"A<B" is the same as "B>A".


Chromium

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 176, 178. handle_enumerator_win.cc 178


string16 GetAccessString(HandleType handle_type,
                         ACCESS_MASK access) {
  ....
  if (access & FILE_WRITE_ATTRIBUTES)
    output.append(ASCIIToUTF16("\tFILE_WRITE_ATTRIBUTES\n"));
  if (access & FILE_WRITE_DATA)
    output.append(ASCIIToUTF16("\tFILE_WRITE_DATA\n"));
  if (access & FILE_WRITE_EA)
    output.append(ASCIIToUTF16("\tFILE_WRITE_EA\n"));
  if (access & FILE_WRITE_EA)
    output.append(ASCIIToUTF16("\tFILE_WRITE_EA\n"));
  break;
  ....
}

WebM

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 755, 758. vp8_cx_iface.c 758


static vpx_codec_err_t vp8e_encode(....)
{
  vpx_codec_err_t res = VPX_CODEC_OK;

  if (!ctx->cfg.rc_target_bitrate)
    return res;

  if (!ctx->cfg.rc_target_bitrate)
    return res;
  ....
}

Chromium

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 259, 261. profile_sync_service_password_unittest.cc 261


static bool PasswordFormComparator(const PasswordForm& pf1,
                                   const PasswordForm& pf2) {
  if (pf1.submit_element < pf2.submit_element)
    return true;
  if (pf1.username_element < pf2.username_element)
    return true;
  if (pf1.username_value < pf2.username_value)
    return true;
  if (pf1.username_value < pf2.username_value)
    return true;
  if (pf1.password_element < pf2.password_element)
    return true;
  if (pf1.password_value < pf2.password_value)
    return true;

  return false;
}

Asterisk

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 2513, 2516. chan_sip.c 2516


static void sip_threadinfo_destructor(void *obj)
{
  struct sip_threadinfo *th = obj;
  struct tcptls_packet *packet;

  if (th->alert_pipe[1] > -1) {            // <=
    close(th->alert_pipe[0]);
  }
  if (th->alert_pipe[1] > -1) {
    close(th->alert_pipe[1]);
  }
  th->alert_pipe[0] = th->alert_pipe[1] = -1;
  ....
}

LibreOffice

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 77, 79. eventoootcontext.cxx 79


XMLTransformerOOoEventMap_Impl::XMLTransformerOOoEventMap_Impl(
        XMLTransformerEventMapEntry *pInit,
        XMLTransformerEventMapEntry *pInit2 )
{
  if( pInit )
    AddMap( pInit );
  if( pInit )
    AddMap( pInit2 );
}

Unreal Engine 4

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 1334, 1340. foliageedmode.cpp 1340


void FEdModeFoliage::ReapplyInstancesForBrush(....)
{
  ....
  if (Settings->ReapplyScaleY)
  {
    Instance.DrawScale3D.Y = NewScale.Y;
    bUpdated = true;
  }

  if (Settings->ReapplyScaleY)
  {
    Instance.DrawScale3D.Z = NewScale.Z;
    bUpdated = true;
  }
  ....
}

FreeSWITCH

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 41, 45. switch_dso.c 45


SWITCH_DECLARE(switch_dso_lib_t) switch_dso_open(....)
{
  HINSTANCE lib;

  lib = LoadLibraryEx(path, NULL, 0);

  if (!lib) {
    LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
  }

  if (!lib) {
    DWORD error = GetLastError();
    *err = switch_mprintf("dll open error [%ul]\n", error);
  }

  return lib;
}

Firebird

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 506, 509. idx.cpp 509


void IDX_create_index(....)
{
  ....
  index_fast_load ifl_data;
  ....
  if (!ifl_data.ifl_duplicates)
    scb->sort(tdbb);

  if (!ifl_data.ifl_duplicates)
    BTR_create(tdbb, creation, selectivity);

  ....
}

Open X-Ray Engine

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 445, 447. base_monster_startup.cpp 447


void CBaseMonster::settings_read(CInifile const * ini,
                                 LPCSTR section,
                                 SMonsterSettings &data)
{
  ....
  if (ini->line_exist(ppi_section,"color_base"))
    sscanf(ini->r_string(ppi_section,"color_base"), "%f,%f,%f",
           &data.m_attack_effector.ppi.color_base.r,
           &data.m_attack_effector.ppi.color_base.g,
           &data.m_attack_effector.ppi.color_base.b);
  if (ini->line_exist(ppi_section,"color_base"))
    sscanf(ini->r_string(ppi_section,"color_gray"), "%f,%f,%f",
           &data.m_attack_effector.ppi.color_gray.r,
           &data.m_attack_effector.ppi.color_gray.g,
           &data.m_attack_effector.ppi.color_gray.b);
  if (ini->line_exist(ppi_section,"color_base"))
    sscanf(ini->r_string(ppi_section,"color_add"), "%f,%f,%f",
           &data.m_attack_effector.ppi.color_add.r,
           &data.m_attack_effector.ppi.color_add.g,
           &data.m_attack_effector.ppi.color_add.b);
  ....
}

Identical errors can be found in some other places:

  • V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 447, 449. base_monster_startup.cpp 449

Inkscape

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 1046, 1051. sp-mesh-array.cpp 1051


void SPMeshNodeArray::create( ...., Geom::OptRect bbox ) // <=
{
  ....
  if( !bbox ) {
    std::cout << "SPMeshNodeArray::create(): bbox empty"
              << std::endl;
    Geom::OptRect bbox = item->geometricBounds();        // <=
  }
  if( !bbox ) {                                          // <=
    std::cout << "ERROR: No bounding box!"
              << std::endl;
    return;
  }
  ....
}

GDB

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 4535, 4537. tracepoint.c 4537


int
handle_tracepoint_bkpts (struct thread_info *tinfo,
                         CORE_ADDR stop_pc)
{
  int ipa_trace_buffer_is_full;
  CORE_ADDR ipa_stopping_tracepoint;
  int ipa_expr_eval_result;
  CORE_ADDR ipa_error_tracepoint;
  ....
  if (ipa_trace_buffer_is_full)
    trace_debug ("lib stopped due to full buffer.");
  if (ipa_stopping_tracepoint)
    trace_debug ("lib stopped due to tpoint");
  if (ipa_stopping_tracepoint)
    trace_debug ("lib stopped due to error");
  ....
}

Linux Kernel

V581 The conditional expressions of the 'if' operators situated alongside each other are identical. Check lines: 2384, 2390. debug.c 2390


int dbg_check_nondata_nodes_order(....)
{
  ....
  sa = container_of(cur, struct ubifs_scan_node, list);
  sb = container_of(cur->next, struct ubifs_scan_node, list);

  if (sa->type != UBIFS_INO_NODE &&
      sa->type != UBIFS_DENT_NODE &&
      sa->type != UBIFS_XENT_NODE) {
    ubifs_err(c, "bad node type %d", sa->type);
    ubifs_dump_node(c, sa->node);
    return -EINVAL;
  }
  if (sa->type != UBIFS_INO_NODE &&
      sa->type != UBIFS_DENT_NODE &&
      sa->type != UBIFS_XENT_NODE) {
    ubifs_err(c, "bad node type %d", sb->type);
    ubifs_dump_node(c, sb->node);
    return -EINVAL;
  }
  ....
}


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;