Examples of errors detected by the V501 diagnostic

<< Return to list of all diagnostics

V501. There are identical sub-expressions to the left and to the right of the 'foo' operator.


Audacity

V501 There are identical sub-expressions to the left and to the right of the '-' operator. Audacity voicekey.cpp 304


sampleCount VoiceKey::OnBackward (....) {
  ...
  int atrend = sgn(buffer[samplesleft - 2]-
                   buffer[samplesleft - 1]);
  int ztrend = sgn(buffer[samplesleft - WindowSizeInt-2]-
                   buffer[samplesleft - WindowSizeInt-2]);
  ...
}

A Copy-Paste error. In the last line 1 should be subtracted instead of 2.


Crystal Space 3D SDK

V501 There are identical sub-expressions to the left and to the right of the '&&' operator. plgcsopcode icelss.h 69


inline_ bool Contains(const LSS& lss)
{
  // We check the LSS contains the two spheres
  // at the start and end of the sweep
  return Contains(Sphere(lss.mP0, lss.mRadius)) &&
         Contains(Sphere(lss.mP0, lss.mRadius));
}

A Copy-Paste error. The lss.mP1 variable should have been probably used when calling the Sphere function for the second time.


Shareaza

V501 There are identical sub-expressions to the left and to the right of the '==' operator: nCmd == nCmd Shareaza wndpacket.cpp 477


void CPacketWnd::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
{
  ...

  if ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 )
  {
    m_bTypeED = ( nCmd == nCmd ) ? TRUE : FALSE;
  }
  ...
}

Xpdf

V501 There are identical sub-expressions to the left and to the right of the '||' operator: ( res -> pw == 0 ) || ( res -> pw == 0 ) mupdf pi.c 219


static bool pi_next_rpcl(opj_pi_iterator_t * pi) {
  ...
  if ((res->pw==0)||(res->pw==0)) continue;

  ...
}

Most likely this is what should be written here: (res->pw==0)||(res->ph==0).


XUIFramework

V501 There are identical sub-expressions to the left and to the right of the '||' operator. Borne resizedlg.cpp 157


HDWP CItemCtrl::OnSize(....)
{
  ...
  if (m_styTop == CST_ZOOM ||
      m_styTop == CST_ZOOM ||
      m_styBottom == CST_DELTA_ZOOM ||
      m_styBottom == CST_DELTA_ZOOM)
  ...
}

Most likely this is what should be written here: m_styBottom == CST_ZOOM || m_styBottom == CST_DELTA_ZOOM.


Ultimate Toolbox

V501 There are identical sub-expressions to the left and to the right of the '&&' operator. UT ox3dtabview.cpp 230


void COX3DTabViewContainer::OnNcPaint()
{
  ...
  if(rectClient.top<rectClient.bottom &&
     rectClient.top<rectClient.bottom)
  {
    dc.ExcludeClipRect(rectClient);
  }
  ...
}

Identical errors can be found in some other places:

  • V501 There are identical sub-expressions to the left and to the right of the '&&' operator. UT oxtabclientwnd.cpp 184

Ultimate Toolbox

V501 There are identical sub-expressions to the left and to the right of the '==' operator: dwDockStyle == dwDockStyle UT oxframewnddock.cpp 190


void COXFrameWndSizeDock::TileDockedBars(
  DWORD dwDockStyle)
{
  ...
  if (pDock != NULL &&
      (pDock->m_dwStyle &&
       dwDockStyle == dwDockStyle))
  ...
}

Probably some other expression should be written instead of "dwDockStyle == dwDockStyle".


Ultimate Toolbox

V501 There are identical sub-expressions to the left and to the right of the '&&' operator. UT oxscrollwnd.cpp 645


void COXScrollWnd::OnPrepareDC(....)
{
  ...
  ASSERT(m_totalDev.cx>=0 && m_totalDev.cx>=0);
  ...
}

This is what should have been written here: ASSERT(m_totalDev.cx>=0 && m_totalDev.cy>=0);

Identical errors can be found in some other places:

  • V501 There are identical sub-expressions to the left and to the right of the '&&' operator. UT oxzoomvw.cpp 179

Fennec Media

V501 There are identical sub-expressions to the left and to the right of the '&&' operator: a -> tsize && a -> tsize media library.c 1076


int fennec_tag_item_compare(struct fennec_audiotag_item *a,
  struct fennec_audiotag_item *b)
{
  int v;
  if(a->tsize && a->tsize)
    v = abs(str_cmp(a->tdata, a->tdata));
  else
    v = 1;
  return v;
}

Notepad++

V501 There are identical sub-expressions to the left and to the right of the '&&' operator: _isPointXValid && _isPointXValid


bool _isPointXValid;
bool _isPointYValid;

bool isPointValid() {
  return _isPointXValid && _isPointXValid;
};

WinMerge

V501 There are identical sub-expressions to the left and to the right of the '||' operator


BUFFERTYPE m_nBufferType[2];
...
// Handle unnamed buffers
if ((m_nBufferType[nBuffer] == BUFFER_UNNAMED) ||
    (m_nBufferType[nBuffer] == BUFFER_UNNAMED))
  nSaveErrorCode = SAVE_NO_FILENAME;

If we look at the code nearby, the following should be written here by analogy: (m_nBufferType[0] == BUFFER_UNNAMED) || (m_nBufferType[1] == BUFFER_UNNAMED).


eLynx Image Processing SDK and Lab

V501 There are identical sub-expressions to the left and to the right of the '/' operator: sizeof (ms_pfList) / sizeof (ms_pfList) IFF plugins engine.cpp 955

V501 There are identical sub-expressions to the left and to the right of the '/' operator: sizeof (ms_bmList) / sizeof (ms_bmList) IFF plugins engine.cpp 958


void uteTestRunner::StressBayer(uint32 iFlags)
{
  ...
  static EPixelFormat ms_pfList[] =
    { PF_Lub, PF_Lus, PF_Li, PF_Lf, PF_Ld };
  const int fsize = sizeof(ms_pfList) / sizeof(ms_pfList);

  static EBayerMatrix ms_bmList[] =
    { BM_GRBG, BM_GBRG, BM_RGGB, BM_BGGR, BM_None };
  const int bsize = sizeof(ms_bmList) / sizeof(ms_bmList);
  ...
}

This is what should have been written here: sizeof(ms_pfList) / sizeof(ms_pfList[0]) and sizeof(ms_bmList) / sizeof(ms_bmList[0]).


eLynx Image Processing SDK and Lab

V501 There are identical sub-expressions 'sizeof (ms_2boolean)' to the left and to the right of the '/' operator. ImageVariant checkformatconversion.cpp 72


void checkFormatConversion::Test(....)
{
  ...
  static struct { bool _b1, _b2; } ms_2boolean[] = {
    { false, false },
    { false, true  },
    { true,  false },
    { true,  true  }
  };
  const int b2size = sizeof(ms_2boolean) / sizeof(ms_2boolean);
  ...
}

This is what should have been written here: sizeof(ms_2boolean) / sizeof(ms_2boolean)

Identical errors can be found in some other places:

  • V501 There are identical sub-expressions to the left and to the right of the '/' operator: sizeof (ms_list) / sizeof (ms_list) ImageVariant checkformatconversion.cpp 99
  • V501 There are identical sub-expressions 'sizeof (ms_ColorSpace)' to the left and to the right of the '/' operator. ImageVariant checkformatconversion.cpp 172
  • V501 There are identical sub-expressions to the left and to the right of the '/' operator: sizeof (ms_bmList) / sizeof (ms_bmList) ImageVariant checkformatconversion.cpp 436

RunAsAdmin Explorer Shim

V501 There are identical sub-expressions to the left and to the right of the '==' operator: luid2.HighPart == luid2.HighPart RAACommon raacommonfuncs.cpp 1511


bool IsLuidsEqual(LUID luid1, LUID luid2)
{
  return (luid1.LowPart == luid2.LowPart) &&
         (luid2.HighPart == luid2.HighPart);
}

This is what should have been written here: (luid1.HighPart == luid2.HighPart).


EchoVNC

V501 There are identical sub-expressions to the left and to the right of the '||' operator: fHorzSize < 0 || fHorzSize < 0 PicLibAPI picture.cpp 347


bool CPicture::Draw(....)
{
  ...
  if (fHorzSize < 0 || fHorzSize < 0 ) {
    return false;
  }
  ...
}

Lugaru

V501 There are identical sub-expressions '(mainmenu && gameon)' to the left and to the right of the '||' operator. Lugaru gamedraw.cpp 2237

V501 There are identical sub-expressions '(!gameon && gamestarted)' to the left and to the right of the '||' operator. Lugaru gamedraw.cpp 2237


int Game::DrawGLScene(void)
{
  ...
  if(freeze||winfreeze||(mainmenu&&gameon)||
     (!gameon&&gamestarted)||(mainmenu&&gameon)||
     (!gameon&&gamestarted)||(!gameon&&gamestarted))
  {
    multiplier=tempmult;
  }
  ...
}

Lugaru

V501 There are identical sub-expressions '(!gameon && gamestarted)' to the left and to the right of the '||' operator. Lugaru gamedraw.cpp 3960


int Game::DrawGLScene(void)
{
  ...
  if(freeze||winfreeze||(mainmenu&&gameon)||
     (!gameon&&gamestarted)||(!gameon&&gamestarted))
  {
    tempmult=multiplier;
    multiplier=0;
  }
  ...
}

Lugaru

V501 There are identical sub-expressions 'Compare (consoletext [0], "belt ", 0, 4)' to the left and to the right of the '||' operator. Lugaru gametick.cpp 5515


void  Game::Tick()
{
  ...
  if(Compare(consoletext[0],"belt ",0,4)||
     Compare(consoletext[0],"belt ",0,4))
  {
    player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
    donesomething=1;
  }
  ...
}

The word "belt" should start both with the capital and small letters.


TickerTape

V501 There are identical sub-expressions 'm_GamePad [iUserIndex].sThumbLX' to the left and to the right of the '||' operator. TickerTape dxutcamera.cpp 479


void CBaseCamera::GetInput(....)
{
  ...
  if( m_GamePad[iUserIndex].wButtons ||
      m_GamePad[iUserIndex].sThumbLX ||
      m_GamePad[iUserIndex].sThumbLX ||
      m_GamePad[iUserIndex].sThumbRX ||
      m_GamePad[iUserIndex].sThumbRY ||
      m_GamePad[iUserIndex].bLeftTrigger ||
      m_GamePad[iUserIndex].bRightTrigger )
  {
    m_GamePadLastActive[iUserIndex] = DXUTGetTime();
  }
  ...
}

This is what should have been written here: m_GamePad[iUserIndex].sThumbLX || m_GamePad[iUserIndex].sThumbLY ||.


IPP Samples

V501 There are identical sub-expressions 'p_newHeader.pic_parameter_set_id' to the left and to the right of the '!=' operator. h264_spl umc_h264_au_stream.cpp 478

V501 There are identical sub-expressions 'p_newHeader.field_pic_flag' to the left and to the right of the '!=' operator. h264_spl umc_h264_au_stream.cpp 479


bool H264_AU_Stream::IsPictureSame(
  H264SliceHeaderParse & p_newHeader)
{
  if ((p_newHeader.frame_num !=
       m_lastSlice.frame_num) ||
      (p_newHeader.pic_parameter_set_id !=
       p_newHeader.pic_parameter_set_id) ||
      (p_newHeader.field_pic_flag !=
       p_newHeader.field_pic_flag) ||
      (p_newHeader.bottom_field_flag !=
       m_lastSlice.bottom_field_flag)
      ){
      return false;
  }
  ...
}

The code is formatted. That's why the error is clearly seen. In reality, such errors are difficult to find. 'p_newHeader' is used in two places instead of 'm_lastSlice' here.


IPP Samples

V501 There are identical sub-expressions to the left and to the right of the '<' operator: (m_cur.AcRate [2]) < (m_cur.AcRate [2]) me umc_me.cpp 898


void MeBase::MakeVlcTableDecision()
{
  ...
  Ipp32s BestMV =
    IPP_MIN(IPP_MIN(m_cur.MvRate[0],m_cur.MvRate[1]),
                    IPP_MIN(m_cur.MvRate[2],m_cur.MvRate[3]));
  Ipp32s BestAC =
    IPP_MIN(IPP_MIN(m_cur.AcRate[0],m_cur.AcRate[1]),
                    IPP_MIN(m_cur.AcRate[2],m_cur.AcRate[2]));
  ...
}

See the last string. The index at the end should be '3', not '2'. As a result, the error causes the minimum value to be estimated incorrectly at times.


IPP Samples

V501 There are identical sub-expressions '(mBVOPsearchHorBack)' to the left and to the right of the '>' operator. mpeg4_enc mp4_enc_misc.cpp 547


Ipp32s ippVideoEncoderMPEG4::Init(mp4_Param *par)
{
  ...
  i = IPP_MAX(mBVOPsearchHorBack, mBVOPsearchHorBack);
  ...
}

By analogy with the nearby code, the second variable should be mBVOPsearchVerBack instead of mBVOPsearchHorBack. This is the correct code: i = IPP_MAX(mBVOPsearchHorBack, mBVOPsearchVerBack).


IPP Samples

V501 There are identical sub-expressions to the left and to the right of the '-' operator: state->freq - state->freq speech ec_fb.c 250


int ec_fb_GetSubbandNum(void *stat)
{
    _fbECState *state=(_fbECState *)stat;
    return (state->freq-state->freq);
}

Something wrong has been subtracted. I don't know what the code should look like exactly, but this is obviously an error. The function always returns 0.


IPP Samples

V501 There are identical sub-expressions 'm_pContext->m_seqLayerHeader->heightMB' to the left and to the right of the '&&' operator. vc1_dec umc_vc1_video_decoder.cpp 1347


Status VC1VideoDecoder::ResizeBuffer()
{
  ...
  if(m_pContext && m_pContext->m_seqLayerHeader &&
     m_pContext->m_seqLayerHeader->heightMB &&
     m_pContext->m_seqLayerHeader->heightMB)
  ...
}

This is what should have been written here: m_pContext->m_seqLayerHeader->heightMB && m_pContext->m_seqLayerHeader->widthMB.


IT++

V501 There are identical sub-expressions 'mseq1.get_length ()' to the left and to the right of the '==' operator. itpp_mkl sequence.cpp 126


Gold::Gold(const ivec &mseq1_connections,
           const ivec &mseq2_connections)
{
  ...
  it_assert(mseq1.get_length() == mseq1.get_length(),
            "Gold::Gold(): dimension mismatch");
}

This assert never works.


SAGA GIS

V501 There are identical sub-expressions 'pSandInput->Get_NY ()' to the left and to the right of the '==' operator. grid_analysis soil_texture.cpp 180


bool CSoil_Texture::On_Execute(void)
{
  ...
  if (pSandInput->Get_NX()==pClayInput->Get_NX() &&
      pSandInput->Get_NY()==pSandInput->Get_NY() )
  ...
}

Miranda IM

V501 There are identical sub-expressions to the left and to the right of the '||' operator: !pStatusList ||!ppUserList ||!ppUserList chat manager.c 1333


USERINFO* UM_AddUser(STATUSINFO* pStatusList,
  USERINFO** ppUserList, const TCHAR* pszUID,
  const TCHAR* pszNick, WORD wStatus)
{
  ...
  if (!pStatusList || !ppUserList || !ppUserList)
    return NULL;
  ...
}

Identical errors can be found in some other places:

  • V501 There are identical sub-expressions to the left and to the right of the '||' operator: !pStatusList ||!ppUserList ||!ppUserList scriver manager.c 1119
  • V501 There are identical sub-expressions to the left and to the right of the '||' operator: !pStatusList ||!ppUserList ||!ppUserList tabsrmm manager.cpp 1265

Miranda IM

V501 There are identical sub-expressions 'job->hOwner' to the left and to the right of the '&&' operator. tabsrmm hotkeyhandler.cpp 564


LONG_PTR CALLBACK HotkeyHandlerDlgProc(....)
{
  ...
  if (job->hOwner && job->iAcksNeeded && job->hOwner &&
      job->iStatus == SendQueue::SQ_INPROGRESS) {
  ...
}

Miranda IM

V501 There are identical sub-expressions 'user->statusMessage' to the left and to the right of the '&&' operator. jabber jabber_chat.cpp 214


void CJabberProto::GcLogShowInformation(....)
{
  ...
  if (user->statusMessage && user->statusMessage)
  ...
}

StrongDC++

V501 There are identical sub-expressions 'line [linelen] != '\r'' to the left and to the right of the '&&' operator. miniupnpc miniupnpc.c 153


static voidgetContentLengthAndHeaderLength(....)
{
  ...
  while(line[linelen] != '\r' && line[linelen] != '\r')
  ...
}

Chromium

V501 There are identical sub-expressions to the left and to the right of the '||' operator. browser web_database.cc 404


bool AutoFillProfileHasName(const AutoFillProfile& profile) {
  return
   !profile.GetFieldText(AutofillType(NAME_FIRST)).empty() ||
   !profile.GetFieldText(AutofillType(NAME_MIDDLE)).empty() ||
   !profile.GetFieldText(AutofillType(NAME_MIDDLE)).empty();
}

Chromium

V501 There are identical sub-expressions 'host != buzz::XmlConstants::str_empty ()' to the left and to the right of the '&&' operator. chromoting_jingle_glue iq_request.cc 248


void JingleInfoRequest::OnResponse(....) {
  ...
  std::string host = server->Attr(buzz::QN_JINGLE_INFO_HOST);
  std::string port_str = server->Attr(buzz::QN_JINGLE_INFO_UDP);
  if (host != buzz::STR_EMPTY && host != buzz::STR_EMPTY) {
  ...
}

Most likely this is what should be written here: (host != buzz::STR_EMPTY && port_str != buzz::STR_EMPTY).


Libjingle

V501 There are identical sub-expressions to the left and to the right of the '&&' operator: !has_audio &&!has_audio libjingle_p2p sessionmessages.cc 308


bool ParseGingleTransportInfos(....)
{
  ...
  bool has_audio =
    FindContentInfoByName(contents, CN_AUDIO) != NULL;
  bool has_video =
    FindContentInfoByName(contents, CN_VIDEO) != NULL;

  if (!has_audio && !has_audio) {
    ...
}

This is what should have been written here: if (!has_audio && !has_video) {


Libxml2

V501 There are identical sub-expressions 'sub->negNsSet->value' to the left and to the right of the '==' operator. libxml xmlschemas.c 13949


static int
xmlSchemaCheckCOSNSSubset(....)
{
  ...
  if ((sub->negNsSet != NULL) &&
      (super->negNsSet != NULL) &&
      (sub->negNsSet->value == sub->negNsSet->value))
   return 0;
 ...
}

This is what should have been written here: (sub->negNsSet->value == super->negNsSet->value))


Mesa 3D Graphics Library

V501 There are identical sub-expressions 'ir1->operands [0]->type->is_matrix ()' to the left and to the right of the '||' operator. mesa ir_algebraic.cpp 189


bool
ir_algebraic_visitor::reassociate_constant(....)
{
  ...
  if (ir1->operands[0]->type->is_matrix() ||
      ir1->operands[0]->type->is_matrix() ||
      ir2->operands[1]->type->is_matrix() ||
      ir2->operands[1]->type->is_matrix())
   return false;
  ...
}

Mesa 3D Graphics Library

V501 There are identical sub-expressions to the left and to the right of the '&&' operator: width > 0 && height > 0 && height > 0 mesa teximage.c 2801


void GLAPIENTRY
_mesa_TexSubImage3D(....)
{
  ...
  else if (width > 0 && height > 0 && height > 0) {
  ...
}

This is what should have been written here: else if (width > 0 && height > 0 && depth > 0) {


Skia Graphics Engine

V501 There are identical sub-expressions 'kKeep_StencilOp == fFrontFailOp' to the left and to the right of the '&&' operator. skia grstencil.h 159


bool isDisabled() const {
  return kKeep_StencilOp == fFrontPassOp   &&
         kKeep_StencilOp == fBackPassOp    &&
         kKeep_StencilOp == fFrontFailOp   &&
         kKeep_StencilOp == fFrontFailOp   &&
         kAlways_StencilFunc == fFrontFunc &&
         kAlways_StencilFunc == fBackFunc;
}

Here we seem to have several errors at once. Besides the repeating condition, && and || may be mixed up.


EA WebKit

V501 There are identical sub-expressions 'x >= 0' to the left and to the right of the '&&' operator. webcore_platform feconvolvematrix.cpp 289


ALWAYS_INLINE int
FEConvolveMatrix::getPixelValue(
  PaintingData& paintingData, int x, int y)
{
  if (x >= 0 &&
      x < paintingData.width &&
      x >= 0 &&
      y < paintingData.height)
    return (y * paintingData.width + x) << 2;
  ...
}

This is what should have been written here: y >= 0 && y < paintingData.height


EA WebKit

V501 There are identical sub-expressions '(bStart >= aStart && bStart <= aEnd)' to the left and to the right of the '||' operator. webcore_remaining spatialnavigation.cpp 236


// This method checks if |start| and
// |dest| have a partial intersection, either
// horizontally or vertically.
// * a = Current focused node's rect.
// * b = Focus candidate node's rect.
static bool areRectsPartiallyAligned(....)
{
    int aStart  = start(direction, a);
    int bStart  = start(direction, b);
    int bMiddle = middle(direction, b);
    int aEnd = end(direction, a);
    int bEnd = end(direction, b);

    // Picture of the partially aligned logic:
    //
    //    Horizontal       Vertical
    // ********************************
    // *  _            *   _ _ _      *
    // * |_|           *  |_|_|_|     *
    // * |_|.... _     *      . .     *
    // * |_|    |_|    *      . .     *
    // * |_|....|_|    *      ._._ _  *
    // *        |_|    *      |_|_|_| *
    // *        |_|    *              *
    // *               *              *
    // ********************************
    //
    // ... and variants of the above cases.
    return ((bStart >= aStart && bStart <= aEnd)
            || (bStart >= aStart && bStart <= aEnd)
            || (bEnd >= aStart && bEnd <= aEnd)
            || (bMiddle >= aStart && bMiddle <= aEnd)
            || (bEnd >= aStart && bEnd <= aEnd));
}

The (bStart >= aStart && bStart <= aEnd) comparison is repeated twice. I cannot say for sure what should be written instead of this.


EA WebKit

V501 There are identical sub-expressions 'cy().isRelative()' to the left and to the right of the '||' operator. webcore_svg svgradialgradientelement.cpp 253


bool SVGRadialGradientElement::selfHasRelativeLengths() const
{
  return cy().isRelative()
      || cy().isRelative()
      || r().isRelative()
      || fx().isRelative()
      || fy().isRelative();
}

This is what should have been written here: return cx().isRelative() || cy().isRelative() || .....


QT

V501 There are identical sub-expressions to the left and to the right of the '-' operator: orig->y1 - orig->y1 QtGui qbezier.cpp 329


static ShiftResult shift(....)
{
  ...
  qreal l = (orig->x1 - orig->x2)*(orig->x1 - orig->x2) +
            (orig->y1 - orig->y2)*(orig->y1 - orig->y1) *
            (orig->x3 - orig->x4)*(orig->x3 - orig->x4) +
            (orig->y3 - orig->y4)*(orig->y3 - orig->y4);
  ...
}

Seems like it should be "orig->y1 - orig->y2" instead of "orig->y1 - orig->y1".


QT

V501 There are identical sub-expressions to the left and to the right of the '||' operator: iw <= 0 || iw <= 0 QtGui qfontengine_win.cpp 1103


QNativeImage *QFontEngineWin::drawGDIGlyph(....)
{
  ...
  int iw = gm.width.toInt();
  int ih = gm.height.toInt();

  if (iw <= 0 || iw <= 0)
    return 0;
  ...
}

This is what should have been written here: if (iw <= 0 || ih <= 0)


QT

V501 There are identical sub-expressions 'State_Sunken' to the left and to the right of the '|' operator. QtGui qwindowsstyle.cpp 1365


void QWindowsStyle::drawPrimitive(....)
{
  ....
  } else if (flags & (State_Raised | State_Sunken |
                      State_On | State_Sunken))
  {
  ....
}

One 'State_Sunken' constant is unnecessary here - something else should be written instead of it.


QT

V501 There are identical sub-expressions to the left and to the right of the '&&' operator. Qt3Support q3richtext.cpp 6978


Q3TextCustomItem* Q3TextDocument::parseTable(....)
{
  ...
  while (end < length
    && !hasPrefix(doc, length, end, QLatin1String("</td"))
    && !hasPrefix(doc, length, end, QLatin1String("<td"))
    && !hasPrefix(doc, length, end, QLatin1String("</th"))
    && !hasPrefix(doc, length, end, QLatin1String("<th"))
    && !hasPrefix(doc, length, end, QLatin1String("<td"))
    && !hasPrefix(doc, length, end, QLatin1String("</tr"))
    && !hasPrefix(doc, length, end, QLatin1String("<tr"))
    && !hasPrefix(doc, length, end, QLatin1String("</table"))
  ) {
  ....
}

The "td" prefix is being searched for twice.


QT

V501 There are identical sub-expressions to the left and to the right of the '&&' operator. QtOpenGL qglextensions.cpp 367


bool qt_resolve_glsl_extensions(QGLContext *ctx)
{
  ...
  return glCreateShader &&
    glShaderSource &&
    glCompileShader &&
    glDeleteProgram &&      <<<---
    glCreateProgram &&
    glAttachShader &&
    glDetachShader &&
    glLinkProgram &&
    glUseProgram &&
    glDeleteProgram &&      <<<---
    glGetShaderInfoLog &&
    glGetShaderiv &&
    glGetShaderSource &&
    glGetProgramiv &&
    glGetProgramInfoLog &&
    glGetUniformLocation &&
    glUniform1fv &&
    glUniform2fv &&
    glUniform3fv &&
    glUniform4fv &&
    glUniform1i &&
    glUniform1iv &&
    glUniformMatrix2fv &&
    glUniformMatrix3fv &&
    glUniformMatrix4fv &&
    glBindAttribLocation &&
    glGetAttribLocation &&
    glVertexAttrib1fv &&
    glVertexAttrib2fv &&
    glVertexAttrib3fv &&
    glVertexAttrib4fv &&
    glVertexAttribPointer &&
    glDisableVertexAttribArray &&
    glEnableVertexAttribArray;
  ...
}

There's no error. It's just an unnecessary line. It is still useful to find and fix such code fragments: your code will become a bit shorter.


QT

V501 There are identical sub-expressions to the left and to the right of the '||' operator: ignoreTrans || ignoreTrans QtDeclarative qdeclarativestategroup.cpp 400


void QDeclarativeStateGroupPrivate::setCurrentStateInternal(....)
{
  ...
  QDeclarativeTransition *transition =
    (ignoreTrans || ignoreTrans) ?
        0 :
        findTransition(currentState, state);
  ...
}

Strange... But maybe not an error. There are no other suitable variables.


QT

V501 There are identical sub-expressions to the left and to the right of the '&&' operator. QtWebKit renderstyle.h 162


bool operator==(const InheritedFlags& other) const
{
  ...
  return
    (_empty_cells == other._empty_cells) &&
    (_caption_side == other._caption_side) &&
    (_list_style_type == other._list_style_type) &&
    (_list_style_position == other._list_style_position) &&
    (_visibility == other._visibility) &&
    (_text_align == other._text_align) &&
    (_text_transform == other._text_transform) &&       <<<---
    (_text_decorations == other._text_decorations) &&
    (_text_transform == other._text_transform) &&       <<<---
    (_cursor_style == other._cursor_style) &&
    (_direction == other._direction) &&
    (_border_collapse == other._border_collapse) &&
    (_white_space == other._white_space) &&
    (_box_direction == other._box_direction) &&
    (_visuallyOrdered == other._visuallyOrdered) &&
    (_htmlHacks == other._htmlHacks) &&
    (_force_backgrounds_to_white ==
     other._force_backgrounds_to_white) &&
    (_pointerEvents == other._pointerEvents);
  ...
}

There's no error. It's just an unnecessary line. It is still useful to find and fix such code fragments: your code will become a bit shorter.


QT

V501 There are identical sub-expressions to the left and to the right of the '&&' operator: mt.pbFormat && mt.pbFormat phonon_ds9 videorenderer_soft.cpp 462


QSize VideoRendererSoftFilter::videoSize() const
{
  ...
  if (mt.pbFormat && mt.pbFormat) {
  ...
}

Most likely this is what should be written here: if (mt.pbFormat && mt.cbFormat) {


MySQL

V501 There are identical sub-expressions to the left and to the right of the '&&' operator: val != end && val != end sql item_timefunc.cc


static date_time_format_types
get_date_time_result_type(const char *format, uint length)
{
  ...
  for (; val != end && val != end; val++)
  ...
}

Apache HTTP Server

V501 There are identical sub-expressions 'state == rsl_encoding' to the left and to the right of the '||' operator. mod_mime_magic mod_mime_magic.c 787


static int magic_rsl_to_request(request_rec *r)
{
  ...
  if (state == rsl_subtype || state == rsl_encoding ||
      state == rsl_encoding) {
  ...
}

This is what should have been written here: (state == rsl_subtype || state == rsl_separator || state == rsl_encoding).


OpenWsman

V501 There are identical sub-expressions to the left and to the right of the '&&' operator: name && uri && name OpenWsmanLib wsman-xml.c 156


static char *make_qname(
    WsXmlNodeH node, const char *uri, const char *name)
{
  char *buf = NULL;
  if (name && uri && name) {
  ...
}

Most likely this is what should be written here: (node && uri && name).


Intel AMT SDK

V501 There are identical sub-expressions 'options->delivery_password' to the left and to the right of the '||' operator. OpenWsmanLib wsman-client.c 631


static void
wsman_set_subscribe_options(....)
{
  ...
  if(options->delivery_certificatethumbprint ||
     options->delivery_password ||
     options->delivery_password) {
  ...
}

The password is checked twice, while the options->delivery_username variable is not checked.


Clang

V501 There are identical sub-expressions 'LBO->hasNoUnsignedWrap ()' to the left and to the right of the '&&' operator. LLVMAnalysis instructionsimplify.cpp 1891


static Value *SimplifyICmpInst(....) {
  ...
  case Instruction::Shl: {
    bool NUW = LBO->hasNoUnsignedWrap() &&
               LBO->hasNoUnsignedWrap();
    bool NSW = LBO->hasNoSignedWrap() &&
               RBO->hasNoSignedWrap();
  ...
}

Most likely this is what should be written here: bool NUW = LBO->hasNoUnsignedWrap() && RBO->hasNoUnsignedWrap();


Clang

V501 There are identical sub-expressions 'LBO->hasNoUnsignedWrap ()' to the left and to the right of the '&&' operator. LLVMAnalysis instructionsimplify.cpp 1891


static Value *SimplifyICmpInst(....) {
  ...
  case Instruction::Shl: {
    bool NUW = LBO->hasNoUnsignedWrap() &&
               LBO->hasNoUnsignedWrap();
    bool NSW = LBO->hasNoSignedWrap() &&
               RBO->hasNoSignedWrap();
  ...
}

Most likely this is what should be written here: bool NUW = LBO->hasNoUnsignedWrap() && RBO->hasNoUnsignedWrap();


Clang

V501 There are identical sub-expressions 'FoldMskICmp_Mask_AllZeroes' to the left and to the right of the '|' operator. LLVMInstCombine instcombineandorxor.cpp 505

V501 There are identical sub-expressions 'FoldMskICmp_Mask_NotAllZeroes' to the left and to the right of the '|' operator. LLVMInstCombine instcombineandorxor.cpp 509


static unsigned getTypeOfMaskedICmp(....)
{
  ...
  result |= (icmp_eq ? (FoldMskICmp_Mask_AllZeroes |
                        FoldMskICmp_Mask_AllZeroes |
                        FoldMskICmp_AMask_Mixed |
                        FoldMskICmp_BMask_Mixed)
                     : (FoldMskICmp_Mask_NotAllZeroes |
                        FoldMskICmp_Mask_NotAllZeroes |
                        FoldMskICmp_AMask_NotMixed |
                        FoldMskICmp_BMask_NotMixed));
  ...
}

Clang

V501 There are identical sub-expressions to the left and to the right of the '||' operator: Op1I->hasOneUse () || Op1I->hasOneUse () LLVMInstCombine instcombineandorxor.cpp 2246


Instruction *InstCombiner::visitXor(BinaryOperator &I) {
  ...
  if (Op0I && Op1I && Op0I->isShift() &&
      Op0I->getOpcode() == Op1I->getOpcode() &&
      Op0I->getOperand(1) == Op1I->getOperand(1) &&
      (Op1I->hasOneUse() || Op1I->hasOneUse())) {
  ...
}

Most likely this is what should be written here: (Op0I->hasOneUse() || Op1I->hasOneUse()).


Clang

V501 There are identical sub-expressions to the left and to the right of the '==' operator: Src1.FloatVal == Src1.FloatVal LLVMInterpreter execution.cpp 425

V501 There are identical sub-expressions to the left and to the right of the '==' operator: Src2.FloatVal == Src2.FloatVal LLVMInterpreter execution.cpp 426

V501 There are identical sub-expressions to the left and to the right of the '==' operator: Src1.DoubleVal == Src1.DoubleVal LLVMInterpreter execution.cpp 428

V501 There are identical sub-expressions to the left and to the right of the '==' operator: Src2.DoubleVal == Src2.DoubleVal LLVMInterpreter execution.cpp 429


static GenericValue executeFCMP_ORD(GenericValue Src1,
                                    GenericValue Src2,
                                    Type *Ty) {
  GenericValue Dest;
  if (Ty->isFloatTy())
    Dest.IntVal = APInt(1,(Src1.FloatVal == Src1.FloatVal &&
                           Src2.FloatVal == Src2.FloatVal));
  else
    Dest.IntVal = APInt(1,(Src1.DoubleVal == Src1.DoubleVal &&
                           Src2.DoubleVal == Src2.DoubleVal));
  return Dest;
}

Clang

V501 There are identical sub-expressions to the left and to the right of the '!=' operator: Src1.FloatVal != Src1.FloatVal LLVMInterpreter execution.cpp 437

V501 There are identical sub-expressions to the left and to the right of the '!=' operator: Src2.FloatVal != Src2.FloatVal LLVMInterpreter execution.cpp 438

V501 There are identical sub-expressions to the left and to the right of the '!=' operator: Src1.DoubleVal != Src1.DoubleVal LLVMInterpreter execution.cpp 440

V501 There are identical sub-expressions to the left and to the right of the '!=' operator: Src2.DoubleVal != Src2.DoubleVal LLVMInterpreter execution.cpp 441


static GenericValue executeFCMP_UNO(GenericValue Src1,
                                    GenericValue Src2,
                                    Type *Ty) {
  GenericValue Dest;
  if (Ty->isFloatTy())
    Dest.IntVal = APInt(1,(Src1.FloatVal != Src1.FloatVal ||
                           Src2.FloatVal != Src2.FloatVal));
  else
    Dest.IntVal = APInt(1,(Src1.DoubleVal != Src1.DoubleVal ||
                           Src2.DoubleVal != Src2.DoubleVal));
  return Dest;
}

Clang

V501 There are identical sub-expressions to the left and to the right of the '&&' operator: CurChar != '\n' && CurChar != '\n' LLVMMCParser asmlexer.cpp 149


AsmToken AsmLexer::LexLineComment() {
  // FIXME: This is broken if we happen to a comment
  // at the end of a file, which was .included, and
  // which doesn't end with a newline.
  int CurChar = getNextChar();
  while (CurChar != '\n' && CurChar != '\n' && CurChar != EOF)
    CurChar = getNextChar();
  ...
}

Most likely this is what should be written here: (CurChar != '\n' && CurChar != '\r' && CurChar != EOF).


Clang

V501 There are identical sub-expressions to the left and to the right of the '||' operator. LLVMSelectionDAG dagcombiner.cpp 7340


bool DAGCombiner::SimplifySelectOps(....) {
  ...
  LoadSDNode *LLD = cast<LoadSDNode>(LHS);
  LoadSDNode *RLD = cast<LoadSDNode>(RHS);
  ...
  if ((LLD->hasAnyUseOfValue(1) &&
       (LLD->isPredecessorOf(CondLHS) ||
        LLD->isPredecessorOf(CondRHS))) ||
      (LLD->hasAnyUseOfValue(1) &&
       (LLD->isPredecessorOf(CondLHS) ||
        LLD->isPredecessorOf(CondRHS))))
    return false;
  ...
}

A Copy-Paste error. The programmer seems to have forgotten to replace LLD with RLD in three places.


Clang

V501 There are identical sub-expressions '!DAG.isKnownNeverZero (LHS)' to the left and to the right of the '&&' operator. LLVMX86CodeGen x86isellowering.cpp 11635


static SDValue PerformSELECTCombine(....)
{
  ...
  SDValue LHS = N->getOperand(1);
  SDValue RHS = N->getOperand(2);

  ...
  if (!UnsafeFPMath &&
      !DAG.isKnownNeverZero(LHS) &&
      !DAG.isKnownNeverZero(RHS))
  ...
  if (!UnsafeFPMath &&
      !DAG.isKnownNeverZero(LHS) &&
      !DAG.isKnownNeverZero(LHS))
  ...
}

Maybe RHS should be used in the last line, not LHS.


Clang

V501 There are identical sub-expressions 'CondResult.isInvalid()' to the left and to the right of the '||' operator. clangSema semastmt.cpp 899


StmtResult
Sema::ActOnDoStmt(....)
{
  ...
  ExprResult CondResult = CheckBooleanCondition(Cond, DoLoc);
  if (CondResult.isInvalid() || CondResult.isInvalid())
    return StmtError();
  ...
}

Clang

V501 There are identical sub-expressions 'P->isMemberPointerType ()' to the left and to the right of the '&&' operator. clangSema sematemplatededuction.cpp 3240


Sema::DeduceTemplateArguments(....)
{
  ...
  if ((P->isPointerType() && A->isPointerType()) ||
      (P->isMemberPointerType() && P->isMemberPointerType()))
  ...
}

This is what should have been written here: (P->isMemberPointerType() && A->isMemberPointerType()).


ReactOS

V501 There are identical sub-expressions to the left and to the right of the '&&' operator: str [0] == '\\' && str [0] == '\\' urlmon uri.c 273


static inline BOOL is_unc_path(const WCHAR *str) {
  return (str[0] == '\\' && str[0] == '\\');
}

ReactOS

V501 There are identical sub-expressions 'SetLocalTime (lpSystemTime)' to the left and to the right of the '&&' operator. timedate dateandtime.c 51


BOOL
SystemSetLocalTime(LPSYSTEMTIME lpSystemTime)
{
  ...
  Ret = SetLocalTime(lpSystemTime) &&
        SetLocalTime(lpSystemTime);
  ...
}

Identical errors can be found in some other places:

  • V501 There are identical sub-expressions 'SetLocalTime (& SetupData->SystemTime)' to the left and to the right of the '&&' operator. syssetup wizard.c 1398

ReactOS

V501 There are identical sub-expressions '_ILIsControlPanel (pidl)' to the left and to the right of the '||' operator. shell32 she_ocmenu.c 1222


HRESULT
SHEOW_LoadOpenWithItems(SHEOWImpl *This, IDataObject *pdtobj)
{
  ...
  if (_ILIsDesktop(pidl) || _ILIsMyDocuments(pidl) ||
      _ILIsControlPanel(pidl) || _ILIsNetHood(pidl) ||
      _ILIsBitBucket(pidl) || _ILIsDrive(pidl) ||
      _ILIsCPanelStruct(pidl) || _ILIsFolder(pidl) ||
      _ILIsControlPanel(pidl))
  {
    TRACE("pidl is a folder\n");
    SHFree((void*)pidl);
    return E_FAIL;
  }
  ...
}

You have to strain your eyes, but if you look closely, you will notice that _ILIsControlPanel(pidl) is repeated twice.


ReactOS

V501 There are identical sub-expressions 'item->member.para.pCell' to the left and to the right of the '&&' operator. riched20 writer.c 254


static BOOL
ME_StreamOutRTFFontAndColorTbl(....)
{
  ...
  if (item->member.para.pCell && item->member.para.pCell)
  ...
}

ReactOS

V501 There are identical sub-expressions to the left and to the right of the '||' operator. ole32 filelockbytes.c 139


static HRESULT WINAPI FileLockBytesImpl_QueryInterface(
  ILockBytes *iface, REFIID riid, void **ppvObject)
{
  if (IsEqualIID(riid, &IID_ILockBytes) ||
      IsEqualIID(riid, &IID_ILockBytes))
    *ppvObject = iface;
  ...
}

ReactOS

V501 There are identical sub-expressions to the left and to the right of the '==' operator: sizeof (GUID) == sizeof (GUID) ntoskrnl events.c 180


NTSTATUS
PopAddRemoveSysCapsCallback(....)
{
   else if (
     RtlCompareMemory(&Notification->Event,
                      &GUID_DEVICE_INTERFACE_REMOVAL,
                      sizeof(GUID) == sizeof(GUID)))
}

A parenthesis is in a wrong place! A closing parenthesis should be placed after the first operator 'sizeof': "sizeof(GUID)) == sizeof(GUID))".

Identical errors can be found in some other places:

  • V501 There are identical sub-expressions to the left and to the right of the '==' operator: sizeof (GUID) == sizeof (GUID) ntoskrnl events.c 178

ReactOS

V501 There are identical sub-expressions '* ScanString == L'\"'' to the left and to the right of the '||' operator. kernel32 proc.c 2326


BOOL
CreateProcessInternalW(....)
{
  ...
  if (*ScanString == L'\"' ||
      *ScanString == L'^' ||
      *ScanString == L'\"')
  ...
}

ReactOS

V501 There are identical sub-expressions to the left and to the right of the '&' operator: dwEnabledOptions & dwEnabledOptions jscript jscript.c 905


static HRESULT WINAPI
JScriptSafety_SetInterfaceSafetyOptions(....)
{
  ...
  This->safeopt = dwEnabledOptions & dwEnabledOptions;
  ...
}

ReactOS

V501 There are identical sub-expressions 'sizeof (mag [0][0])' to the left and to the right of the '/' operator. glu32 mapdescv.cc 131


REAL
Mapdesc::calcPartialVelocity (....)
{
  ...
  const int istride = sizeof(tmp[0]) / sizeof(tmp[0][0][0]);
  const int jstride = sizeof(tmp[0][0]) / sizeof(tmp[0][0][0]);
  const int mistride = sizeof(mag[0]) / sizeof(mag[0][0]);
  const int mjstride = sizeof(mag[0][0]) / sizeof(mag[0][0]);
  ...
}

This is what should have been written here: mjstride = sizeof(mag[0][0]) / sizeof(mag[0][0][0]);


ReactOS

V501 There are identical sub-expressions '!(types [i + 1] & PathPointTypeBezier)' to the left and to the right of the '||' operator. gdiplus graphics.c 925


static GpStatus draw_poly(....)
{
  if((i + 2 >= count)
     || !(types[i + 1] & PathPointTypeBezier)
     || !(types[i + 1] & PathPointTypeBezier)) {
}

IPP Samples

V501 There are identical sub-expressions '(srcB->depth == 16)' to the left and to the right of the '||' operator. ipl iplmpy2d.c 457


IPLFUN(void, iplMpyRCPack2D,
       (IplImage* srcA, IplImage* srcB, IplImage* dst))
{
  ...
  if( (srcA->depth == IPL_DEPTH_8U ) ||
      (srcB->depth == IPL_DEPTH_8U ) ||
      (srcB->depth == IPL_DEPTH_16U) ||
      (srcB->depth == IPL_DEPTH_16U) ||
      (srcA->depth == IPL_DEPTH_1U ) ||
      (srcB->depth == IPL_DEPTH_1U ) )
  ...
}

This is what should have been written here: (srcA->depth == IPL_DEPTH_16U) || (srcB->depth == IPL_DEPTH_16U) ||


IPP Samples

V501 There are identical sub-expressions to the left and to the right of the '-' operator: state->freq - state->freq speech ec_fb.c 253


int ec_fb_GetSubbandNum(void* stat)
{
  _fbECState* state = (_fbECState*)stat;
  return (state->freq - state->freq);
}

Chromium

V501 There are identical sub-expressions 'tempPosition.isNull ()' to the left and to the right of the '||' operator. webcore_remaining accessibilityobject.cpp 489


static VisiblePosition updateAXLineStartForVisiblePosition(....)
{
  ...
  tempPosition = startPosition.previous();
  if (tempPosition.isNull() || tempPosition.isNull())
      break;
  ...
}

Chromium

V501 There are identical sub-expressions 'sizeof (threadcounts)' to the left and to the right of the '/' operator. base_unittests shared_memory_unittest.cc 231


TEST(SharedMemoryTest, MultipleThreads) {
  ...
  int threadcounts[] = { 1, kNumThreads };
  for (size_t i = 0;
       i < sizeof(threadcounts) / sizeof(threadcounts); i++) {
  ...
}

This is what should have been written here: i < sizeof(threadcounts) / sizeof(*threadcounts).


OGRE

V501 There are identical sub-expressions to the left and to the right of the '||' operator. OgreMain ogreparticlesystem.cpp 1358


void ParticleSystem::increaseEmittedEmitterPool(size_t size)
{
  ...
  if (clonedEmitter->getDuration() > 0.0f &&
      (clonedEmitter->getRepeatDelay() > 0.0f ||
       clonedEmitter->getMinRepeatDelay() > 0.0f ||
       clonedEmitter->getMinRepeatDelay() > 0.0f))
   clonedEmitter->setEnabled(false);
  ...
}

Mozilla Firefox

V501 There are identical sub-expressions 'unit [0] == eCSSUnit_Null' to the left and to the right of the '||' operator. nsstyleanimation.cpp 1767


PRBool
nsStyleAnimation::AddWeighted(....)
{
  ...
  if (unit[0] == eCSSUnit_Null || unit[1] == eCSSUnit_Null ||
      unit[0] == eCSSUnit_Null || unit[0] == eCSSUnit_URL) {
    return PR_FALSE;
  }
  ...
}

There seem to be 2 errors at once. The second line in the condition should look like this: unit[0] == eCSSUnit_URL || unit[1] == eCSSUnit_URL.


Mozilla Firefox

V501 There are identical sub-expressions to the left and to the right of the '||' operator. nsdisplaylist.cpp 767


static PRBool IsZPositionLEQ(nsDisplayItem* aItem1,
                             nsDisplayItem* aItem2,
                             void* aClosure) {
  if (!aItem1->GetUnderlyingFrame()->Preserves3D() ||
      !aItem1->GetUnderlyingFrame()->Preserves3D()) {
    return IsContentLEQ(aItem1, aItem2, aClosure);
  }
  ...
}

Most likely this is what should be written here: !aItem1->.... || !aItem2->....


Mozilla Firefox

V501 There are identical sub-expressions to the left and to the right of the '&&' operator: aXResolution > 0.0 && aXResolution > 0.0 nspresshell.cpp 5114


nsresult PresShell::SetResolution(float aXResolution,
                                  float aYResolution)
{
  if (!(aXResolution > 0.0 && aXResolution > 0.0)) {
    return NS_ERROR_ILLEGAL_VALUE;
  }
  ...
}

This is what should have been written here: (aXResolution > 0.0 && aYResolution > 0.0)


Mozilla Firefox

V501 There are identical sub-expressions 'protocol.EqualsIgnoreCase ("ftp")' to the left and to the right of the '||' operator. mozinlinespellwordutil.cpp 1034


if (protocol.EqualsIgnoreCase("http") ||
    protocol.EqualsIgnoreCase("https") ||
    protocol.EqualsIgnoreCase("news") ||
    protocol.EqualsIgnoreCase("ftp") ||          <<<---
    protocol.EqualsIgnoreCase("file") ||
    protocol.EqualsIgnoreCase("javascript") ||
    protocol.EqualsIgnoreCase("ftp")) {          <<<---

Mozilla Firefox

V501 There are identical sub-expressions to the left and to the right of the '||' operator. svgorientsmiltype.cpp 161


nsresult
SVGOrientSMILType::Interpolate(....)
{
  ...
  if (aStartVal.mU.mOrient.mOrientType !=
      nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE ||
      aStartVal.mU.mOrient.mOrientType !=
      nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE)
  {
    // TODO: it would be nice to be able
    // to handle auto angles too.
    return NS_ERROR_FAILURE;
  }
  ...
}

Quake-III-Arena

V501 There are identical sub-expressions '(result->flags & 64)' to the left and to the right of the '||' operator. botlib be_ai_move.c 3236


void BotMoveToGoal(....)
{
  ...
  if ((result->flags & MOVERESULT_ONTOPOF_FUNCBOB) ||
      (result->flags & MOVERESULT_ONTOPOF_FUNCBOB))
  {
    ms->reachability_time = AAS_Time() + 5;
  }
  ...
}

Quake-III-Arena

V501 There are identical sub-expressions 'fabs(dir[1]) > test->radius' to the left and to the right of the '||' operator. q3map lightv.c 1962


int VL_FindAdjacentSurface(....)
{
  ...
  if (fabs(dir[0]) > test->radius ||
      fabs(dir[1]) > test->radius ||
      fabs(dir[1]) > test->radius)
  {
  ...
}

Scintilla

V501 There are identical sub-expressions 'ch == '/'' to the left and to the right of the '||' operator. lexmmixal.cxx 40


inline bool isMMIXALOperator(char ch) {
  if (isascii(ch) && isalnum(ch))
    return false;
  if (ch == '+' || ch == '-' || ch == '|' || ch == '^' ||
      ch == '*' || ch == '/' || ch == '/' ||
      ch == '%' || ch == '<' || ch == '>' || ch == '&' ||
      ch == '~' || ch == '$' ||
      ch == ',' || ch == '(' || ch == ')' ||
      ch == '[' || ch == ']')
    return true;
  return false;
}

Dolphin Emulator

V501 There are identical sub-expressions '~ComputeKnownZeroBits(Op1)' to the left and to the right of the '&' operator. Core ir.cpp 1215


bool IRBuilder::maskedValueIsZero(InstLoc Op1, InstLoc Op2) const
{
  return (~ComputeKnownZeroBits(Op1) &
          ~ComputeKnownZeroBits(Op1)) == 0;
}

ADAPTIVE Communication Environment (ACE)

V501 There are identical sub-expressions 'url_string[pos + 1] == '/'' to the left and to the right of the '&&' operator. INet urlbase.cpp 205


bool URL_Base::strip_scheme (ACE_CString& url_string)
{
  ...
  ACE_CString::size_type pos = url_string.find (':');
  if (pos > 0 &&
      url_string[pos+1] == '/' &&
      url_string[pos+1] == '/')
  {
    ...
    // skip '<protocol>://'
    url_string = url_string.substr (pos+3);
  }
  ...
}

Most likely this is what should be written here: url_string[pos+1] == '/' && url_string[pos+2] == '/'.


WinMerge

V501 There are identical sub-expressions to the left and to the right of the '||' operator: c == L'}' || c == L'}' Merge ccrystaleditview.cpp 1556


bool
isopenbrace (TCHAR c)
{
  return c == _T ('{') || c == _T ('(') ||
         c == _T ('[') || c == _T ('<');
}

bool
isclosebrace (TCHAR c)
{
  return c == _T ('}') || c == _T ('}') ||
         c == _T (']') || c == _T ('>');
}

The variable in the second function is compared to '} twice. A comparison to the ')' character is missing.


WinMerge

V501 There are identical sub-expressions 'pView1->GetTextBufferEol(line)' to the left and to the right of the '!=' operator. Merge mergedoclinediffs.cpp 216


void CMergeDoc::Computelinediff(
  CCrystalTextView *pView1, CCrystalTextView *pView2, ....)
{
  ....
  if (pView1->GetTextBufferEol(line) !=
      pView1->GetTextBufferEol(line))
  ....
}

Clang

V501 There are identical sub-expressions 'SM.getExpansionColumnNumber(ContainerREnd)' to the left and to the right of the '>=' operator. clangStaticAnalyzerCore bugreporter.cpp 925


bool EdgeBuilder::containsLocation(
  const PathDiagnosticLocation &Container,
  const PathDiagnosticLocation &Containee)
{
  ...
  return (ContainerBegLine <= ContaineeBegLine &&
          ContainerEndLine >= ContaineeEndLine &&
          (ContainerBegLine != ContaineeBegLine ||
           SM.getExpansionColumnNumber(ContainerRBeg) <=
           SM.getExpansionColumnNumber(ContaineeRBeg)) &&
          (ContainerEndLine != ContaineeEndLine ||
           SM.getExpansionColumnNumber(ContainerREnd) >=
           SM.getExpansionColumnNumber(ContainerREnd)));
}

The ContaineeREnd variable should have been used in the last line instead of ContainerREnd. You don't see the difference? Spell the words.


Clang

V501 There are identical sub-expressions 'Ty2->isIntegerType()' to the left and to the right of the '&&' operator. SampleAnalyzerPlugin svalbuilder.h 81


bool haveSameType(QualType Ty1, QualType Ty2) {
  return (Context.getCanonicalType(Ty1) ==
          Context.getCanonicalType(Ty2) ||
          (Ty2->isIntegerType() &&
           Ty2->isIntegerType()));
}

Blender

V501 There are identical sub-expressions to the left and to the right of the '>=' operator: start >= start bf_python_bmesh bmesh_py_types_customdata.c 442

V501 There are identical sub-expressions to the left and to the right of the '>=' operator: stop >= stop bf_python_bmesh bmesh_py_types_customdata.c 443


static PyObject *bpy_bmlayercollection_subscript_slice(
  BPy_BMLayerCollection *self,
  Py_ssize_t start, Py_ssize_t stop)
{
  ...
  if (start >= start) start = len - 1;
  if (stop >= stop)   stop  = len - 1;
  ...
}

Blender

V501 There are identical sub-expressions to the left and to the right of the '||' operator: (res->pw == 0) || (res->pw == 0) extern_openjpeg pi.c 219


typedef struct opj_pi_resolution {
  int pdx, pdy;
  int pw, ph;
} opj_pi_resolution_t;

static bool pi_next_rpcl(opj_pi_iterator_t * pi) {
  ...
  if ((res->pw==0)||(res->pw==0)) continue;
  ...
}

Most likely this is what should be written here: (res->pw==0)||(res->ph==0).

Identical errors can be found in some other places:

  • V501 There are identical sub-expressions to the left and to the right of the '||' operator: (res->pw == 0) || (res->pw == 0) extern_openjpeg pi.c 300
  • V501 There are identical sub-expressions to the left and to the right of the '||' operator: (res->pw == 0) || (res->pw == 0) extern_openjpeg pi.c 379

MAME

V501 There are identical sub-expressions 'offset != (0x370 >> 1)' to the left and to the right of the '&&' operator. decoprot.c 118

V501 There are identical sub-expressions 'offset != (0x3c0 >> 1)' to the left and to the right of the '&&' operator. decoprot.c 118


WRITE16_HANDLER( deco16_104_prot_w )
{
  ...
  if (offset != (0x150 >> 1) &&
      offset != (0x0 >> 1) &&
      offset != (0x110 >> 1) &&
      offset != (0x280 >> 1) &&
      offset != (0x290 >> 1) &&
      offset != (0x2b0 >> 1) &&
      offset != (0x370 >> 1) &&   <<<---
      offset != (0x3c0 >> 1) &&   <<<===
      offset != (0x370 >> 1) &&   <<<---
      offset != (0x3c0 >> 1) &&   <<<===
      offset != (0x430 >> 1) &&
      offset != (0x460 >> 1) &&
      offset != (0x5a0 >> 1) &&
      offset != (0x5b0 >> 1) &&
      offset != (0x6e0 >> 1) &&
      offset != (0x7d0 >> 1)
  )
  ...
}

Identical errors can be found in some other places:

  • V501 There are identical sub-expressions 'offset != 0x2c / 2' to the left and to the right of the '&&' operator. decoprot.c 240
  • V501 There are identical sub-expressions 'offset != 0xe' to the left and to the right of the '&&' operator. decoprot.c 447

Trans-Proteomic Pipeline

V501 There are identical sub-expressions 'szPeptide[i + 1] != 'P'' to the left and to the right of the '&&' operator. Comet_fastadb comet-fastadb1.cxx 1906


void DIGEST_PROTEIN(char *szSeq,
       int iLenSeq)
{
  ...
  if (pOptions.bMarkNXST
      && szPeptide[i] == 'N'
      && szPeptide[i + 1] != 'P'
      && (szPeptide[i + 2] == 'S' ||
          szPeptide[i + 2] == 'T')
      && szPeptide[i + 1] != 'P')
  ...
}

The index in the last line should be this: [i + 3].


Visualization Toolkit (VTK)

V501 There are identical sub-expressions 'newPos[2] != oldPos[2]' to the left and to the right of the '||' operator. vtkCharts vtkpiecewisecontrolpointsitem.cxx 129


void vtkPiecewiseControlPointsItem::SetControlPoint(
  vtkIdType index, double* newPos)
{
  double oldPos[4];
  this->PiecewiseFunction->GetNodeValue(index, oldPos);
  if (newPos[0] != oldPos[0] || newPos[1] != oldPos[1] ||
      newPos[2] != oldPos[2] || newPos[2] != oldPos[2])
    {
      this->PiecewiseFunction->SetNodeValue(index, newPos);
    }
}

A misprint. The last array items are not compared.


Visualization Toolkit (VTK)

V501 There are identical sub-expressions to the left and to the right of the '-' operator: outExt[0] - outExt[0] vtkFiltering vtkdatasetattributes.cxx 457

V501 There are identical sub-expressions to the left and to the right of the '-' operator: outExt[2] - outExt[2] vtkFiltering vtkdatasetattributes.cxx 458

V501 There are identical sub-expressions to the left and to the right of the '-' operator: outExt[4] - outExt[4] vtkFiltering vtkdatasetattributes.cxx 459

V501 There are identical sub-expressions to the left and to the right of the '-' operator: outExt[0] - outExt[0] vtkFiltering vtkdatasetattributes.cxx 490

V501 There are identical sub-expressions to the left and to the right of the '-' operator: outExt[2] - outExt[2] vtkFiltering vtkdatasetattributes.cxx 491

V501 There are identical sub-expressions to the left and to the right of the '-' operator: outExt[4] - outExt[4] vtkFiltering vtkdatasetattributes.cxx 492


template <class iterT>
void vtkDataSetAttributesCopyValues(....)
{
  ...
  inZPtr +=
    (outExt[0]-outExt[0])*inIncs[0] * data_type_size +
    (outExt[2] - outExt[2])*inIncs[1] * data_type_size +
    (outExt[4] - outExt[4])*inIncs[2] * data_type_size;
  ...
}

Meaningless code. It's equivalent to inZPtr += 0;


Visualization Toolkit (VTK)

V501 There are identical sub-expressions 'this->GetMTime() > this->BuildTime' to the left and to the right of the '||' operator. vtkFiltering vtkdiscretizablecolortransferfunction.cxx 85


void vtkDiscretizableColorTransferFunction::Build()
{
  ...
  if (this->Discretize &&
      (this->GetMTime() > this->BuildTime ||
       this->GetMTime() > this->BuildTime))
  ...
}

Visualization Toolkit (VTK)

V501 There are identical sub-expressions to the left and to the right of the '||' operator: gridType == 11 || gridType == 11 vtkHybrid vtktransformtogrid.cxx 184


void vtkTransformToGrid::UpdateShiftScale()
{
  int gridType = this->GridScalarType;
  if (gridType == VTK_DOUBLE || gridType == VTK_DOUBLE)
  ...
}

Visualization Toolkit (VTK)

V501 There are identical sub-expressions to the left and to the right of the '>=' operator: allocateExtent[1] >= allocateExtent[1] vtkImaging vtkimagestencildata.cxx 1178


void vtkImageStencilRaster::PrepareForNewData(....)
{
  ...
  if (allocateExtent &&
      allocateExtent[1] >= allocateExtent[1])
  ...
}

Visualization Toolkit (VTK)

V501 There are identical sub-expressions '(minX > imageViewportSize[0] - 1 && maxX > imageViewportSize[0] - 1)' to the left and to the right of the '||' operator. vtkVolumeRendering vtkfixedpointvolumeraycastmapper.cxx 2184


int vtkFixedPointVolumeRayCastMapper::ComputeRowBounds(....)
{
  if ( ( minX < 0 && maxX < 0 ) ||
       ( minY < 0 && maxY < 0 ) ||
       ( minX > imageViewportSize[0]-1 &&
         maxX > imageViewportSize[0]-1 ) ||
       ( minX > imageViewportSize[0]-1 &&
         maxX > imageViewportSize[0]-1 ) )
  ...
}

The consequences of the Copy-Paste method. A null index is used everywhere.


Visualization Toolkit (VTK)

V501 There are identical sub-expressions '(mat[0 * 4 + 3] != 0)' to the left and to the right of the '||' operator. vtkVolumeRendering vtkprojectedtetrahedramapper.cxx 134


template<class point_type>
void vtkProjectedTetrahedraMapperTransformPoints(....)
{
  ...
  if (   (mat[0*4+3] != 0) || (mat[1*4+3] != 0)
      || (mat[0*4+3] != 0) || (mat[1*4+3] != 1) )
  ...
}

Visualization Toolkit (VTK)

V501 There are identical sub-expressions 'sub->negNsSet->value' to the left and to the right of the '==' operator. vtklibxml2 xmlschemas.c 13873


static int
xmlSchemaCheckCOSNSSubset(xmlSchemaWildcardPtr sub,
                          xmlSchemaWildcardPtr super)
{
  ...
  if ((sub->negNsSet != NULL) &&
      (super->negNsSet != NULL) &&
      (sub->negNsSet->value == sub->negNsSet->value))
      return (0);
  ...
}

This is what should have been written here: (sub->negNsSet->value == super->negNsSet->value).


MongoDB

V501 There are identical sub-expressions to the left and to the right of the '==' operator: buildIndexes == buildIndexes rs_config.h 101


bool operator==(const MemberCfg& r) const {
  ....
  return _id==r._id && votes == r.votes &&
         h == r.h && priority == r.priority &&
         arbiterOnly == r.arbiterOnly &&
         slaveDelay == r.slaveDelay &&
         hidden == r.hidden &&
         buildIndexes == buildIndexes;        <<<---
}

ffdshow

V501 There are identical sub-expressions to the left and to the right of the '!=' operator: pict.rectClip != pict.rectClip timgfilterresize.cpp 80


bool TimgFilterResize::is(const TffPictBase &pict,
                          const TfilterSettingsVideo *cfg0)
{
  ...
  return pict.rectFull != newRectFull ||
         pict.rectClip != pict.rectClip;
  ...
}

Samba

V501 There are identical sub-expressions 'ace->type == SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT' to the left and to the right of the '||' operator. sddl.c 528


static char *sddl_encode_ace(TALLOC_CTX *mem_ctx,
                             const struct security_ace *ace,
                             const struct dom_sid *domain_sid)
{
  ....
  if (ace->type == SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT ||
      ace->type == SEC_ACE_TYPE_ACCESS_DENIED_OBJECT ||
      ace->type == SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT ||
      ace->type == SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT) {
  ....
}

Samba

V501 There are identical sub-expressions to the left and to the right of the '!=' operator: s1_len != s1_len pdbtest.c 106


static bool samu_correct(struct samu *s1, struct samu *s2)
{
  ....
  } else if (s1_len != s1_len) {
    DEBUG(0, ("Password history not written correctly, "
              "lengths differ, want %d, got %d\n",
          s1_len, s2_len));
    ret = False;
  }
  ....
}

Samba

V501 There are identical sub-expressions to the left and to the right of the '>' operator: data > data t_asn1.c 45


int main(void)
{
  ....
  if ((data->length != tests[i].length) ||
      (memcmp(data>data, tests[i].data, data->length) != 0)) {
    printf("Test for %d failed\n", values[i]);
    ok = False;
  }
  ....
}

Most likely this is what should be written here: data->data.


Samba

V501 There are identical sub-expressions to the left and to the right of the '>' operator: i2->pid > i2->pid brlock.c 1901


static int compare_procids(const void *p1, const void *p2)
{
  const struct server_id *i1 = (struct server_id *)p1;
  const struct server_id *i2 = (struct server_id *)p2;

  if (i1->pid < i2->pid) return -1;
  if (i2->pid > i2->pid) return 1;
  return 0;
}

OpenSSL

V501 There are identical sub-expressions '!object->data.key' to the left and to the right of the '||' operator. str_lib.c 475


EVP_PKEY *STORE_get_private_key(....)
{
  STORE_OBJECT *object;
  ....
  if (!object || !object->data.key || !object->data.key)
  {
    STOREerr(STORE_F_STORE_GET_PRIVATE_KEY,
             STORE_R_FAILED_GETTING_KEY);
    return 0;
  }
  ....
}

Identical errors can be found in some other places:

  • V501 There are identical sub-expressions '!object->data.key' to the left and to the right of the '||' operator. str_lib.c 616
  • V501 There are identical sub-expressions '!object->data.key' to the left and to the right of the '||' operator. str_lib.c 670
  • V501 There are identical sub-expressions '!object->data.key' to the left and to the right of the '||' operator. str_lib.c 811

OpenCV

V501 There are identical sub-expressions to the left and to the right of the '||' operator: _rvec3 || dr3dr1 || dr3dr1 calibration.cpp 415


CV_IMPL void cvComposeRT(
  const CvMat* _rvec1, const CvMat* _tvec1,
  const CvMat* _rvec2, const CvMat* _tvec2,
  CvMat* _rvec3, CvMat* _tvec3,
  CvMat* dr3dr1, CvMat* dr3dt1,
  CvMat* dr3dr2, CvMat* dr3dt2,
  CvMat* dt3dr1, CvMat* dt3dt1,
  CvMat* dt3dr2, CvMat* dt3dt2)
{
  ....
  if( _rvec3 || dr3dr1 || dr3dr1 )
  ....
}

OpenCV

V501 There are identical sub-expressions 'cmptlut[0] < 0' to the left and to the right of the '||' operator. grfmt_jpeg2000.cpp 215


bool Jpeg2KDecoder::readHeader()
{
  ....
  cmptlut[0] = ....
  cmptlut[1] = ....
  cmptlut[2] = ....
  if( cmptlut[0] < 0 || cmptlut[1] < 0 || cmptlut[0] < 0 )
    result = false;
  ....
}

OpenCV

V501 There are identical sub-expressions to the left and to the right of the '!=' operator: dst_size.height != dst_size.height epilines.cpp 2118


CV_IMPL IplImage* icvCreateIsometricImage(....)
{
  ....
  if( !dst || dst->depth != desired_depth ||
      dst->nChannels != desired_num_channels ||
      dst_size.width != src_size.width ||
      dst_size.height != dst_size.height )
  ....
}

OpenCV

V501 There are identical sub-expressions to the left and to the right of the '!=' operator: cat_var_count != cat_var_count tree.cpp 1415

V501 There are identical sub-expressions to the left and to the right of the '!=' operator: ord_var_count != ord_var_count tree.cpp 1415


void CvDTreeTrainData::read_params(....)
{
  ....
  if( cat_var_count != cat_var_count ||
      ord_var_count != ord_var_count )
    CV_ERROR(CV_StsParseError,
      "var_type is inconsistent with "
      "cat_var_count and ord_var_count");
  ....
}

OpenCV

V501 There are identical sub-expressions to the left and to the right of the '==' operator: M.size() == M.size() imgwarp.cpp 3672


CV_IMPL CvMat*
cv2DRotationMatrix( CvPoint2D32f center, double angle,
                    double scale, CvMat* matrix )
{
  cv::Mat M0 = cv::cvarrToMat(matrix),
          M = cv::getRotationMatrix2D(center, angle, scale);
  CV_Assert( M.size() == M.size() );
  M.convertTo(M0, M0.type());
  return matrix;
}

Identical errors can be found in some other places:

  • V501 There are identical sub-expressions to the left and to the right of the '&&' operator: data && dims >= 1 && data mat.hpp 434
  • V501 There are identical sub-expressions to the left and to the right of the '&&' operator: 0 <= d && _sizes && d <= 32 && _sizes matrix.cpp 186
  • V501 There are identical sub-expressions to the left and to the right of the '==' operator: M.size() == M.size() imgwarp.cpp 3685

ReactOS

V501 There are identical sub-expressions 'src_tex->target != PIPE_TEXTURE_2D' to the left and to the right of the '&&' operator. u_blit.c 421


void util_blit_pixels_writemask(....)
{
  ....
  if ((src_tex == dst_surface->texture &&
      dst_surface->u.tex.level == src_level &&
      dst_surface->u.tex.first_layer == srcZ0) ||
      (src_tex->target != PIPE_TEXTURE_2D &&
      src_tex->target != PIPE_TEXTURE_2D &&
      src_tex->target != PIPE_TEXTURE_RECT))
  ....
}

ReactOS

V501 There are identical sub-expressions 'src->channel[i].type' to the left and to the right of the '!=' operator. translate_generic.c 776


struct util_format_channel_description
{
   unsigned type:5;
   unsigned normalized:1;
   unsigned pure_integer:1;
   unsigned size:9;
};

static boolean
is_legal_int_format_combo(
  const struct util_format_description *src,
  const struct util_format_description *dst )
{
  ....
  for (i = 0; i < nr; i++) {
    /* The signs must match. */
    if (src->channel[i].type != src->channel[i].type) {
      return FALSE;
    }
  ....
}

This is what should have been written here: src->channel[i].type != dst->channel[i].type


ReactOS

V501 There are identical sub-expressions '!(types[i + 1] & PathPointTypeBezier)' to the left and to the right of the '||' operator. graphics.c 1912


static GpStatus draw_poly(....)
{
  ....
  if((i + 2 >= count) ||
     !(types[i + 1] & PathPointTypeBezier) ||
     !(types[i + 1] & PathPointTypeBezier))
  {
    ERR("Bad bezier points\n");
    goto end;
  }
  ....
}

ReactOS

V501 There are identical sub-expressions '!LunExt->IdentifyData.SectorsPerTrack' to the left and to the right of the '||' operator. id_init.cpp 1528


VOID NTAPI UniAtaReadLunConfig(....)
{
  if(!LunExt->IdentifyData.SectorsPerTrack ||
     !LunExt->IdentifyData.NumberOfCylinders ||
     !LunExt->IdentifyData.SectorsPerTrack)
    ....
}

ReactOS

V501 There are identical sub-expressions to the left and to the right of the '||' operator: (ir->from == 0) || (ir->from == 0) ir_validate.cpp 123


ir_visitor_status
ir_validate::visit_leave(ir_loop *ir)
{
  if (ir->counter != NULL) {
    if ((ir->from == NULL) || (ir->from == NULL) ||
        (ir->increment == NULL)) {
  ....
}

This is what should have been written here: (ir->from == NULL) || (ir->to == NULL)

Identical errors can be found in some other places:

  • V501 There are identical sub-expressions to the left and to the right of the '||' operator: (ir->from != 0) || (ir->from != 0) ir_validate.cpp 139

Windows 8 Driver Samples

V501 There are identical sub-expressions 'sizeof (tempString)' to the left and to the right of the '/' operator. utils.c 931


BOOLEAN
DsmpFindSupportedDevice(
    _In_ IN PUNICODE_STRING DeviceName,
    _In_ IN PUNICODE_STRING SupportedDevices
    )
{
  WCHAR tempString[32];
  ....
  tempString[(sizeof(tempString) /
              sizeof(tempString)) - 1] = L'\0';
  ....
}

This is what should have been written here: tempString[(sizeof(tempString) / sizeof(tempString[0])) - 1]


<< Return to list of all diagnostics