Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#2142 PVS-Studio

Trunk
open
nobody
None
5
3 days ago
2013-06-07
Andrey Karpov
No

Hello.

I recheck WinMerge and found same strange code. Perhaps a errors present here. Please verify code.
For check I use PVS-Studio 5.05: http://www.viva64.com/en/pvs-studio/

Previous checks:
http://www.viva64.com/en/b/0082/
http://www.viva64.com/en/b/0139/

-------------------------------------------------------------------------------
V547 Expression 'cchText < 0' is always false. Unsigned type value is never < 0. ccrystaleditview.cpp 1135

BOOL CCrystalEditView::
DoDropText (....)
{
  ....
  UINT cbData = (UINT) ::GlobalSize (hData);
  UINT cchText = cbData / sizeof(TCHAR) - 1;
  if (cchText < 0)
    return FALSE;
  ....
}
-------------------------------------------------------------------------------
V547 Expression 'i >= 0' is always true. Unsigned type value is always >= 0. mergedoclinediffs.cpp 282

void CMergeDoc::Computelinediff(....)
{
  ....
  vector<wdiff*>::size_type i;
  ....
  for (i=worddiffs.size() - 1; i>=0; --i)
  {
    const wdiff * diff = worddiffs[i];
    if (end1 == -1 && diff->end[0] != -1)
      end1 = diff->end[0];
    if (end2 == -1 && diff->end[1] != -1)
      end2 = diff->end[1];
    if (end1 != -1 && end2 != -1)
      break; // found both
  }
  ....
}
-------------------------------------------------------------------------------
WinMerge

V595 The 'm_pOwner' pointer was utilized before it was verified against nullptr. Check lines: 1033, 1035. ccrystaleditview.cpp 1033

BOOL CEditDropTargetImpl::
OnDrop (....)
{
  bool bDataSupported = false;

  m_pOwner->HideDropIndicator ();

  if ((!m_pOwner) ||
      (!(m_pOwner->QueryEditable ())) ||
      (m_pOwner->GetDisableDragAndDrop ()))
  ....
}

And here:
V595 The 'p' pointer was utilized before it was verified against nullptr. Check lines: 714, 720. io.c 714
V595 The 'right' pointer was utilized before it was verified against nullptr. Check lines: 194, 199. side.c 194
V595 The 'm_pTextBuffer' pointer was utilized before it was verified against nullptr. Check lines: 474, 477. ccrystaleditview.cpp 474
V595 The 'rent' pointer was utilized before it was verified against nullptr. Check lines: 608, 611. dirscan.cpp 608
V595 The 'pDirDoc' pointer was utilized before it was verified against nullptr. Check lines: 1214, 1221. mainfrm.cpp 1214
V595 The 'p' pointer was utilized before it was verified against nullptr. Check lines: 71, 84. mergecmdlineinfo.cpp 71
-------------------------------------------------------------------------------
V620 It's unusual that the expression of sizeof(T) kind is being summed with the pointer to T type. vsshelper.cpp 339

int VSSHelper::GetWordFromBuffer(
  TCHAR *inBuffer, DWORD dwInBufferSize,
  TCHAR * outBuffer, DWORD dwOutBufferSize, TCHAR * charset)
{
  ....
  while (buffercount < dwInBufferSize && buffercount < dwOutBufferSize)
  {
    ....
    inBuffer += sizeof(TCHAR);
  }
  ....
}  
-------------------------------------------------------------------------------
V635 Consider inspecting the expression. The length should probably be multiplied by the sizeof(wchar_t). cs2cs.cpp 236

int
iconvert_new (LPCTSTR source, LPTSTR *destination,
              int source_coding, int destination_coding,
              bool alphabet_only)
{
  LPTSTR dest = (LPTSTR) malloc (_tcslen (source) + 1 + 10);
  int result = -3;
  if (dest)
  {
    _tcscpy (dest, source);
    ....
}
-------------------------------------------------------------------------------
V519 The 'code' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 79, 80. timesizecompare.cpp 80

int TimeSizeCompare::CompareFiles(....)
{
  ....
  if (di.left.size != di.right.size)
  {
    code &= ~DIFFCODE::SAME;
    code = DIFFCODE::DIFF;
  }
  ....
}
-------------------------------------------------------------------------------
V519 The 'strParsed' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 345, 347. filefilterhelper.cpp 347

CString FileFilterHelper::ParseExtensions(....) const
{
  ....
  strParsed = _T("^");
  strPattern.MakeLower();
  strParsed = strPattern; //+ _T("$");
  ....
}
-------------------------------------------------------------------------------
V501 There are identical sub-expressions to the left and to the right of the '||' operator: c == L'}' || c == L'}' 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 ('>');
}
-------------------------------------------------------------------------------
V669 The 'sel1' argument is a non-constant reference. The analyzer is unable to determine the position at which this argument is being modified. It is possible that the function contains an error. dirview.cpp 1322

bool CDirView::OpenOneItem(
  UINT_PTR pos1, DIFFITEM **di1, DIFFITEM **di2,
  String &path1, String &path2, int & sel1, bool & isDir)
{
  ....
  // Variable 'sel1' don't modified.
  ....
}
-------------------------------------------------------------------------------

Discussion