SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
Comparing the general static analysis in
Visual Studio 2010 and PVS-Studio by
examples of errors detected in five open
source projects
Authors: Evgeniy Ryzhkov

Date: 20.04.2011


Abstract
The article demonstrates errors detected with the static code analyzer integrated into Visual Studio
2010. The research was performed on five open source projects. The same projects were also checked
with PVS-Studio. Results of comparing these two tools are presented at the end of the article.


Introduction
The article "Difficulties of comparing code analyzers, or don't forget about usability" [1] tells that it is
not so easy to compare two tools as it may seem because the parameter of usability is also highly
significant besides the technical characteristics proper.

Still we cannot do without comparing tools by errors they can detect. Of course, there is no sense in just
calculating the number of errors. So we decided to carry out a practical experiment of error detection in
real projects.

We checked five random open source projects with the static analyzer integrated into Visual Studio
2010 Premium. We looked through the whole message list and chose explicit errors. Then we made the
same steps with PVS-Studio.

Here is a list of projects which participated in the research:

    •   eMule Plus;
    •   Pixie;
    •   VirtualDub;
    •   WinMerge;
    •   XUIFramework.

Let's go!


eMule Plus
The total number of messages generated by the Visual Studio static analyzer is 237, 4 of them being real
errors.

The total number of messages generated by PVS-Studio is 68, 3 of them being real errors.
Visual Studio: warning C6054: String 'szwThemeFile' might not be

zero-terminated. c:emuleplusdialogmintraybtn.hpp 445



WCHAR szwThemeFile[MAX_PATH];

WCHAR szwThemeColor[256];

if (m_themeHelper.GetCurrentThemeName(szwThemeFile,

      ARRSIZE(szwThemeFile), szwThemeColor,

      ARRSIZE(szwThemeColor), NULL, 0) != S_OK)

   return NULL;

WCHAR *p;

if ((p = wcsrchr(szwThemeFile, L'')) == NULL)

Indeed, a line may not end with 0, which will cause potential problems. But in this particular case, this
error is not likely to reveal itself.



Visual Studio: warning C6269: Possibly incorrect order of operations:

dereference ignored. c:emulepluscustomautocomplete.cpp 277



PVS-Studio: V532 Consider inspecting the statement of '*pointer++'

pattern. Probably meant: '(*pointer)++'. customautocomplete.cpp 277



if (pceltFetched != NULL)

   *pceltFetched++;

The programmer here "is not good at" using the (*ptr)++ expression. Although this construct seems to
be rather safe, still this error is widespread.



Visual Studio: warning C6298: Argument '6': using a read-only string

as a writable string argument. This will attempt to write into static

read-only memory and cause random crashes.

c:emuleplusfirewallopener.cpp 183
HRESULT hr = pNSC->AddPortMapping(

   riPortRule.m_strRuleName.AllocSysString(), riPortRule.m_byProtocol,

   riPortRule.m_nPortNumber, riPortRule.m_nPortNumber, 0, L"127.0.0.1",

   ICSTT_IPADDRESS, &pNSPM);

Although it is not an error, the analyzer-generated message is fair. In general, this is a problem of all the
static analyzers. They produce absolutely correct messages but they are far not always real errors. Does
it mean that such tools and messages are useless? No, it does not, because fixing even such warnings
helps to increase an overall quality of code.



Visual Studio: warning C6314: Incorrect order of operations: bitwise-

or has higher precedence than the conditional-expression operator.

Add parentheses to clarify intent. c:emuleplussearchlistctrl.cpp 659



PVS-Studio: V502 Perhaps the '?:' operator works in a different way

than it was expected. The '?:' operator has a lower priority than the

'|' operator.          searchlistctrl.cpp 659



menuSearchFile.AppendMenu( MF_STRING |

   ((iSelectionMark != -1) && (dwSelectedCount > 0) &&

   g_App.m_pServerConnect->IsConnected() &&

   ((pCurServer = g_App.m_pServerConnect->GetCurrentServer())!= NULL)&&

   (pCurServer->GetTCPFlags() & SRV_TCPFLG_RELATEDSEARCH)) ?

      MF_ENABLED : MF_GRAYED, MP_SEARCHRELATED,

         GetResString(IDS_SEARCHRELATED));

Here (because of the construct's complexity) we have wrong priorities of operators. For how long it has
been said... Who prevented the programmer from arranging this code in several separate expressions
instead of writing everything in one line (as it was done in the original program)? No, programmers
would always want to "write it smart".



PVS-Studio: V519 The 'm_clrSample' object is assigned values twice

successively. Perhaps this is a mistake. fontpreviewcombo.cpp 61
CFontPreviewCombo::CFontPreviewCombo()

{

    ...

    m_clrSample = GetSysColor(COLOR_WINDOWTEXT);

    m_clrSample = RGB(60,0,0);

    ...

}



Perhaps the developers wanted to see how the RGB(60,0,0) color would look and forgot to remove it.


Pixie
The total number of messages generated by the Visual Studio static analyzer is 18, 0 of them being real
errors.

The total number of messages generated by PVS-Studio is 65, 5 of them being real errors.

PVS-Studio: V519 The 'numRays' object is assigned values twice

successively. Perhaps this is a mistake. bundles.cpp 579



void CGatherBundle::post() {

 numRays = last;

 numRays = 0;

 last = 0;

 depth++;

}

Oh, how suspicious it is when numRays is first initialized by one value and then by another. Is it an error
or not? Only the code's author knows exactly. But it alerts me!



PVS-Studio: V501 There are identical sub-expressions to the left and

to the right of the '|' operator: PARAMETER_DPDU | PARAMETER_DPDU

quadrics.cpp 880



if (up & (PARAMETER_DPDU | PARAMETER_DPDU)) {
There must be something else here. By the way, here you a general note on fixing errors detected by a
static analyzer. While in some cases correction is obvious and anyone can fix an error, in some other
cases only the author of the code can make out what exactly was intended there. It is on the question if
one could create a tool that can correct errors "like in Word".



PVS-Studio: V501 There are identical sub-expressions to the left and

to the right of the '|' operator: SLC_VECTOR | SLC_VECTOR

expression.cpp 2604



lock(N, getConversion(SLC_VECTOR | SLC_VECTOR,parameters[2]));

SLC_VECTOR mentioned twice in such a context certainly signals an error.



PVS-Studio: V505 The 'alloca' function is used inside the loop.

This can quickly overflow stack. polygons.cpp 1120



inline      void    triangulatePolygon(...) {

  ...

  for (i=1;i<nloops;i++) {

      ...

      do {

        ...

        do {

            ...

            CTriVertex       *snVertex       =    (CTriVertex *)

              alloca(2*sizeof(CTriVertex));

            ...

        } while(dVertex != loops[0]);

        ...

      } while(sVertex != loops[i]);

      ...

  }
...

}

Having deep nesting, the alloca call might cause stack overflow.


VirtualDub
The total number of messages generated by the Visual Studio static analyzer is 24 messages, 0 of them
being real errors.

The total number of messages generated by PVS-Studio is 41, 2 of them being real errors.



PVS-Studio: V547 Expression 'c < 0' is always false.

Unsigned type value is never < 0. lexer.cpp 279



typedef unsigned short wint_t;



wint_t lexgetescape() {

    wint_t c = lexgetc();

    if (c < 0)

     fatal("Newline found in escape sequence");

    ...

}

The code will never be called because the expression is always false.



PVS-Studio: V557 Array overrun is possible. The '9' index is pointing

beyond array bound. f_convolute.cpp 73



struct ConvoluteFilterData {

 long m[9];

 long bias;

 void *dyna_func;

 DWORD dyna_size;

 DWORD dyna_old_protect;
BOOL fClip;

};



static unsigned long __fastcall do_conv(

    unsigned long *data,

    const ConvoluteFilterData *cfd,

    long sflags, long pit)

{

    long rt0=cfd->m[9], gt0=cfd->m[9], bt0=cfd->m[9];

    ...

}

A trivial array overflow.


WinMerge
The total number of messages generated by the Visual Studio static analyzer is 343, 3 of them being real
errors.

The total number of messages generated by PVS-Studio is 69, 12 of them being real errors.

Visual Studio: warning C6313: Incorrect operator: zero-valued flag

cannot be tested with bitwise-and. Use an equality test to check for

zero-valued flags. c:winmergesrcbcmenu.cpp 1489



else if (nFlags&MF_STRING){

 ASSERT(!(nFlags&MF_OWNERDRAW));

 ModifyMenu(pos,nFlags,nID,mdata->GetString());

}

Not very lucky condition. Of course, the programmer wanted to write something different, but it
happened that way.



Visual Studio: warning C6287: Redundant code: the left and right

sub-expressions are identical.

c:winmergesrceditlibccrystaleditview.cpp 1560
PVS-Studio: V501 There are identical sub-expressions to the left and

to the right of the '||' operator: c == '}' || c == '}'

ccrystaleditview.cpp 1560



bool

isclosebrace (TCHAR c)

{

    return c == _T ('}') || c == _T ('}') || c == _T (']')

        || c == _T ('>');

}

Not all the parentheses types are checked. Why? It is usual that "Copy-paste-technology" leads to
errors.



Visual Studio: warning C6287: Redundant code: the left and right

sub-expressions are identical. c:winmergesrcmergedoc.cpp 1165



PVS-Studio: V501 There are identical sub-expressions to the left and

to the right of the '||' operator. mergedoc.cpp 1165



if ((m_nBufferType[nBuffer] == BUFFER_UNNAMED) ||

 (m_nBufferType[nBuffer] == BUFFER_UNNAMED))

     nSaveErrorCode = SAVE_NO_FILENAME;

Another unlucky condition and again it seems to be the copy-paste's fault.



PVS-Studio: V551 The code under this 'case' label is unreachable.

The value range of signed char type: [-128, 127].

ccrystaltextview.cpp 1646



TCHAR ch = strText[i];
switch (ch)

{

    case 0xB7:

    case 0xBB:

      strHTML += ch;

      strHTML += _T("<wbr>");

      bLastCharSpace = FALSE;

      nNonbreakChars = 0;

      break;

And here we have a sample of code which will never be used. Everything seems alright, case is written
and all, but it will never get control because the value range is too narrow. TCHAR in this case is the char
type.



PVS-Studio: V524 It is odd that the body of 'IsValidTextPosX' function

is fully equivalent to the body of 'IsValidTextPos' function

(ccrystaltextview.cpp, line 3700). ccrystaltextview.cpp 3707



bool CCrystalTextView::IsValidTextPos (const CPoint &point)

{

    return GetLineCount () > 0 && m_nTopLine >= 0 &&

             m_nOffsetChar >= 0 && point.y >= 0 &&

             point.y < GetLineCount () && point.x >= 0 &&

             point.x <= GetLineLength (point.y);

}



bool CCrystalTextView::IsValidTextPosX (const CPoint &point)

{

    return GetLineCount () > 0 && m_nTopLine >= 0 &&

             m_nOffsetChar >= 0 && point.y >= 0 &&

             point.y < GetLineCount () && point.x >= 0 &&

             point.x <= GetLineLength (point.y);
}



bool CCrystalTextView::IsValidTextPosY (const CPoint &point)

{

    return GetLineCount () > 0 && m_nTopLine >= 0 &&

             m_nOffsetChar >= 0 && point.y >= 0 &&

             point.y < GetLineCount ();

}

These are very similar functions... The developers copy-pasted again and again and forgot to fix the
result. The IsValidTextPosX() function performs an excess check.



PVS-Studio: V563 It is possible that this 'else' branch must apply to

the previous 'if' statement. bcmenu.cpp 1852



if(IsLunaMenuStyle())

    if(!xp_space_accelerators)return;

else

    if(!original_space_accelerators)return;

Who can look at the code and say exactly to what if else refers? Was it the thing the programmer
wanted to do? Are you sure?



PVS-Studio: V556 The values of different enum types are compared:

switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. diffwrapper.cpp 956



enum output_style {}

...

enum DiffOutputType m_outputStyle;



switch (m_options.m_outputStyle)

{
case OUTPUT_CONTEXT:

enum and switch types were a bit mixed up. But it's alright, isn't it?



PVS-Studio: V530 The return value of function 'empty' is required to

be utilized. diractions.cpp 1307



void CDirView::GetItemFileNames(int sel, String& strLeft,

                                                 String& strRight) const

{

    UINT_PTR diffpos = GetItemKey(sel);

    if (diffpos == (UINT_PTR)SPECIAL_ITEM_POS)

    {

        strLeft.empty();

        strRight.empty();

The case when empty() does not empty. This is an example of an extremely wrong name for a method.



PVS-Studio: V524 It is odd that the body of 'OnUpdateLastdiff'

function is fully equivalent to the body of 'OnUpdateFirstdiff'

function (DirView.cpp, line 2189). dirview.cpp 2220



void CDirView::OnUpdateLastdiff(CCmdUI* pCmdUI)

{

    int firstDiff = GetFirstDifferentItem();

    if (firstDiff > -1)

        pCmdUI->Enable(TRUE);

    else

        pCmdUI->Enable(FALSE);

}



void CDirView::OnUpdateFirstdiff(CCmdUI* pCmdUI)
{

    int firstDiff = GetFirstDifferentItem();

    if (firstDiff > -1)

     pCmdUI->Enable(TRUE);

    else

     pCmdUI->Enable(FALSE);

}

Two more very similar functions...



PVS-Studio: V501 There are identical sub-expressions

'pView1->GetTextBufferEol (line)' to the left and to the right of

the '!=' operator. mergedoclinediffs.cpp 216



if (pView1->GetTextBufferEol(line) !=

     pView1->GetTextBufferEol(line))

{

Either this or that... Or not? Perhaps there must be pView2 here.



PVS-Studio: V530 The return value of function 'empty' is required to

be utilized. varprop.cpp 133



void VariantValue::Clear()

{

    m_vtype = VT_NULL;

    m_bvalue = false;

    m_ivalue = 0;

    m_fvalue = 0;

    m_svalue.empty();

    m_tvalue = 0;

}
Again empty() does not empty the string at all.



PVS-Studio: V510           The 'Format' function is not expected to receive

class-type variable as 'N' actual argument". PropShel 105



String GetSysError(int nerr);

...

CString msg;

msg.Format(

    _T("Failed to open registry key HKCU/%s:nt%d : %s"),

    f_RegDir, retVal, GetSysError(retVal)

    );

When various emergencies occur, WinMerge will try to inform the user about errors but in some cases it
will fail. At first sight everything looks OK but actually the "String" type is just "std::wstring". Therefore
we will print rubbish at best or get an Access Violation error at worst. The correct code must have a call
of c_str().



PVS-Studio: V534 It is likely that a wrong variable is being compared
inside the 'for' operator. Consider reviewing 'i'." BinTrans.cpp 357



// Get length of translated array of bytes from text.

int Text2BinTranslator::iLengthOfTransToBin(

    char* src, int srclen )

{

    ...

    for (k=i; i<srclen; k++)

    {

        if (src[k]=='>')

          break;

    }

    ...
}

The analyzer found a suspicious loop. This code is prone to Access Violation. The loop must go on until it
finds the '>' character or a string with the length of 'srclen' characters comes to an end. But the
programmer by accident used the 'k' variable instead of 'i' for comparison. If the '>' character is not
found, everything will be sad.


XUIFramework
The total number of messages generated by the Visual Studio static analyzer is 93, 2 of them being real
errors.

The total number of messages generated by PVS-Studio is 30, 5 of them being real errors.



Visual Studio: warning C6269: Possibly incorrect order of operations:

dereference ignored

c:xui-gui frameworkwidgetscstatichtmlppdrawmanager.cpp 298



PVS-Studio: V532 Consider inspecting                     the statement of '*pointer++'

pattern. Probably meant: '(*pointer)++'. ppdrawmanager.cpp 298



for (DWORD pixel = 0; pixel < dwWidth * dwHeight; pixel++, *pBits++)

Again the programmer is not good at using *ptr++. As I have said above, this is a widespread error.



Visual Studio: warning C6283: 'pBuffer' is allocated with array new[],

but deleted with scalar delete.

c:xui-gui frameworkwidgetscxstaticcxstatic.cpp 544



BYTE* pBuffer = new BYTE [ nBufferLen ];

...

delete pBuffer;

The programmer confuses delete and delete[]. This causes issues which may occur and may not. But you
should not do so anyway.



PVS-Studio: V519 The 'm_xSt' object is assigned values twice
successively. Perhaps this is a mistake. resizedlg.cpp 244



m_xSt = CST_RESIZE;

m_xSt = CST_RESIZE;

Judging by the code, there must be m_ySt here. But we cannot keep from using copy-paste again and
again, right?



V531 It is odd that a sizeof() operator is multiplied by sizeof().

pphtmldrawer.cpp 258



DWORD dwLen = ::LoadString(hInstDll, dwID, szTemp,

                    (sizeof(szTemp) * sizeof(TCHAR)));

There must be sizeof(szTemp) / sizeof(TCHAR) .



PVS-Studio: V556 The values of different enum types are compared:

enuHAlign == Center. cxstatic.cpp 151



if (enuHAlign == Center)

There must be enuHAlign == Midle. There is also if in the code nearby (enuVAlign == Middle) though it
must be Center. Confusion with enum, in short.



PVS-Studio: V501 There are identical sub-expressions to the left and

to the right of the '||' operator. 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)

    ...

}

Perhaps the code must look this way:

HDWP CItemCtrl::OnSize(...)

{

    ...

    if (m_styTop == CST_ZOOM ||

          m_styTop == CST_DELTA_ZOOM ||

          m_styBottom == CST_ZOOM ||

          m_styBottom == CST_DELTA_ZOOM)

    ...

}


Comparison results




We do not draw any certain conclusions. One of the tools was better in some projects and the other tool
was better in others.


References
    1. Andrey Karpov, Evgeniy Ryzhkov. Difficulties of comparing code analyzers, or don't forget about
       usability. http://www.viva64.com/en/a/0071/.

Weitere ähnliche Inhalte

Was ist angesagt?

Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...PVS-Studio
 
Checking the World of Warcraft CMaNGOS open source server
Checking the World of Warcraft CMaNGOS open source serverChecking the World of Warcraft CMaNGOS open source server
Checking the World of Warcraft CMaNGOS open source serverPVS-Studio
 
Picking Mushrooms after Cppcheck
Picking Mushrooms after CppcheckPicking Mushrooms after Cppcheck
Picking Mushrooms after CppcheckAndrey Karpov
 
Why Windows 8 drivers are buggy
Why Windows 8 drivers are buggyWhy Windows 8 drivers are buggy
Why Windows 8 drivers are buggyPVS-Studio
 
Checking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-xChecking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-xAndrey Karpov
 
Checking 7-Zip with PVS-Studio analyzer
Checking 7-Zip with PVS-Studio analyzerChecking 7-Zip with PVS-Studio analyzer
Checking 7-Zip with PVS-Studio analyzerPVS-Studio
 
A Spin-off: CryEngine 3 SDK Checked with CppCat
A Spin-off: CryEngine 3 SDK Checked with CppCatA Spin-off: CryEngine 3 SDK Checked with CppCat
A Spin-off: CryEngine 3 SDK Checked with CppCatAndrey Karpov
 
PVS-Studio vs Chromium - Continuation
PVS-Studio vs Chromium - ContinuationPVS-Studio vs Chromium - Continuation
PVS-Studio vs Chromium - ContinuationPVS-Studio
 
Reanalyzing the Notepad++ project
Reanalyzing the Notepad++ projectReanalyzing the Notepad++ project
Reanalyzing the Notepad++ projectPVS-Studio
 
Dusting the globe: analysis of NASA World Wind project
Dusting the globe: analysis of NASA World Wind projectDusting the globe: analysis of NASA World Wind project
Dusting the globe: analysis of NASA World Wind projectPVS-Studio
 
A fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBoxA fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBoxPVS-Studio
 
Checking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioChecking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioAndrey Karpov
 
Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code AnalyzerRechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code AnalyzerAndrey Karpov
 
Re-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large reportRe-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large reportPVS-Studio
 
Why Windows 8 drivers are buggy
Why Windows 8 drivers are buggyWhy Windows 8 drivers are buggy
Why Windows 8 drivers are buggyAndrey Karpov
 
Analysis of Godot Engine's Source Code
Analysis of Godot Engine's Source CodeAnalysis of Godot Engine's Source Code
Analysis of Godot Engine's Source CodePVS-Studio
 
Errors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not usedErrors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not usedAndrey Karpov
 
Linux version of PVS-Studio couldn't help checking CodeLite
Linux version of PVS-Studio couldn't help checking CodeLiteLinux version of PVS-Studio couldn't help checking CodeLite
Linux version of PVS-Studio couldn't help checking CodeLitePVS-Studio
 
ChakraCore: analysis of JavaScript-engine for Microsoft Edge
ChakraCore: analysis of JavaScript-engine for Microsoft EdgeChakraCore: analysis of JavaScript-engine for Microsoft Edge
ChakraCore: analysis of JavaScript-engine for Microsoft EdgePVS-Studio
 

Was ist angesagt? (20)

Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
 
Checking the World of Warcraft CMaNGOS open source server
Checking the World of Warcraft CMaNGOS open source serverChecking the World of Warcraft CMaNGOS open source server
Checking the World of Warcraft CMaNGOS open source server
 
Picking Mushrooms after Cppcheck
Picking Mushrooms after CppcheckPicking Mushrooms after Cppcheck
Picking Mushrooms after Cppcheck
 
Why Windows 8 drivers are buggy
Why Windows 8 drivers are buggyWhy Windows 8 drivers are buggy
Why Windows 8 drivers are buggy
 
Checking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-xChecking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-x
 
PVS-Studio vs Clang
PVS-Studio vs ClangPVS-Studio vs Clang
PVS-Studio vs Clang
 
Checking 7-Zip with PVS-Studio analyzer
Checking 7-Zip with PVS-Studio analyzerChecking 7-Zip with PVS-Studio analyzer
Checking 7-Zip with PVS-Studio analyzer
 
A Spin-off: CryEngine 3 SDK Checked with CppCat
A Spin-off: CryEngine 3 SDK Checked with CppCatA Spin-off: CryEngine 3 SDK Checked with CppCat
A Spin-off: CryEngine 3 SDK Checked with CppCat
 
PVS-Studio vs Chromium - Continuation
PVS-Studio vs Chromium - ContinuationPVS-Studio vs Chromium - Continuation
PVS-Studio vs Chromium - Continuation
 
Reanalyzing the Notepad++ project
Reanalyzing the Notepad++ projectReanalyzing the Notepad++ project
Reanalyzing the Notepad++ project
 
Dusting the globe: analysis of NASA World Wind project
Dusting the globe: analysis of NASA World Wind projectDusting the globe: analysis of NASA World Wind project
Dusting the globe: analysis of NASA World Wind project
 
A fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBoxA fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBox
 
Checking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioChecking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-Studio
 
Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code AnalyzerRechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
 
Re-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large reportRe-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large report
 
Why Windows 8 drivers are buggy
Why Windows 8 drivers are buggyWhy Windows 8 drivers are buggy
Why Windows 8 drivers are buggy
 
Analysis of Godot Engine's Source Code
Analysis of Godot Engine's Source CodeAnalysis of Godot Engine's Source Code
Analysis of Godot Engine's Source Code
 
Errors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not usedErrors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not used
 
Linux version of PVS-Studio couldn't help checking CodeLite
Linux version of PVS-Studio couldn't help checking CodeLiteLinux version of PVS-Studio couldn't help checking CodeLite
Linux version of PVS-Studio couldn't help checking CodeLite
 
ChakraCore: analysis of JavaScript-engine for Microsoft Edge
ChakraCore: analysis of JavaScript-engine for Microsoft EdgeChakraCore: analysis of JavaScript-engine for Microsoft Edge
ChakraCore: analysis of JavaScript-engine for Microsoft Edge
 

Andere mochten auch

Checking the Source SDK Project
Checking the Source SDK ProjectChecking the Source SDK Project
Checking the Source SDK ProjectAndrey Karpov
 
Still Comparing "this" Pointer to Null?
Still Comparing "this" Pointer to Null?Still Comparing "this" Pointer to Null?
Still Comparing "this" Pointer to Null?Andrey Karpov
 
PVS-Studio for Visual C++
PVS-Studio for Visual C++PVS-Studio for Visual C++
PVS-Studio for Visual C++Andrey Karpov
 
A Bonus to the "Three Interviews About Static Analyzers" Article, or Intervie...
A Bonus to the "Three Interviews About Static Analyzers" Article, or Intervie...A Bonus to the "Three Interviews About Static Analyzers" Article, or Intervie...
A Bonus to the "Three Interviews About Static Analyzers" Article, or Intervie...Andrey Karpov
 
Checking the Open-Source Multi Theft Auto Game
Checking the Open-Source Multi Theft Auto GameChecking the Open-Source Multi Theft Auto Game
Checking the Open-Source Multi Theft Auto GameAndrey Karpov
 
The Price of Fixing One Bug in Our Programs, or Exotic Bugs in PVS-Studio and...
The Price of Fixing One Bug in Our Programs, or Exotic Bugs in PVS-Studio and...The Price of Fixing One Bug in Our Programs, or Exotic Bugs in PVS-Studio and...
The Price of Fixing One Bug in Our Programs, or Exotic Bugs in PVS-Studio and...Andrey Karpov
 
What's the Difference Between Static Analysis and Compiler Warnings?
What's the Difference Between Static Analysis and Compiler Warnings?What's the Difference Between Static Analysis and Compiler Warnings?
What's the Difference Between Static Analysis and Compiler Warnings?Andrey Karpov
 
Checking PVS-Studio with Clang
Checking PVS-Studio with ClangChecking PVS-Studio with Clang
Checking PVS-Studio with ClangAndrey Karpov
 
Computer & Video Game Archive @MLibrary
Computer & Video Game Archive @MLibraryComputer & Video Game Archive @MLibrary
Computer & Video Game Archive @MLibraryDave Carter
 
Comparison of static code analyzers: CppCat, Cppcheck, PVS-Studio and Visual ...
Comparison of static code analyzers: CppCat, Cppcheck, PVS-Studio and Visual ...Comparison of static code analyzers: CppCat, Cppcheck, PVS-Studio and Visual ...
Comparison of static code analyzers: CppCat, Cppcheck, PVS-Studio and Visual ...Andrey Karpov
 
PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...
PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...
PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...Andrey Karpov
 
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ BuilderA Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ BuilderAndrey Karpov
 
You can now use PVS-Studio with Visual Studio absent; just give it the prepro...
You can now use PVS-Studio with Visual Studio absent; just give it the prepro...You can now use PVS-Studio with Visual Studio absent; just give it the prepro...
You can now use PVS-Studio with Visual Studio absent; just give it the prepro...Andrey Karpov
 
A Long-Awaited Check of Unreal Engine 4
A Long-Awaited Check of Unreal Engine 4A Long-Awaited Check of Unreal Engine 4
A Long-Awaited Check of Unreal Engine 4Andrey Karpov
 
StdAfx.h for Novices
StdAfx.h for NovicesStdAfx.h for Novices
StdAfx.h for NovicesAndrey Karpov
 
Tesseract. Recognizing Errors in Recognition Software
Tesseract. Recognizing Errors in Recognition SoftwareTesseract. Recognizing Errors in Recognition Software
Tesseract. Recognizing Errors in Recognition SoftwareAndrey Karpov
 
Magnificence
MagnificenceMagnificence
MagnificenceBren Dale
 

Andere mochten auch (20)

Checking the Source SDK Project
Checking the Source SDK ProjectChecking the Source SDK Project
Checking the Source SDK Project
 
Still Comparing "this" Pointer to Null?
Still Comparing "this" Pointer to Null?Still Comparing "this" Pointer to Null?
Still Comparing "this" Pointer to Null?
 
PVS-Studio for Visual C++
PVS-Studio for Visual C++PVS-Studio for Visual C++
PVS-Studio for Visual C++
 
A Bonus to the "Three Interviews About Static Analyzers" Article, or Intervie...
A Bonus to the "Three Interviews About Static Analyzers" Article, or Intervie...A Bonus to the "Three Interviews About Static Analyzers" Article, or Intervie...
A Bonus to the "Three Interviews About Static Analyzers" Article, or Intervie...
 
Checking the Open-Source Multi Theft Auto Game
Checking the Open-Source Multi Theft Auto GameChecking the Open-Source Multi Theft Auto Game
Checking the Open-Source Multi Theft Auto Game
 
The Price of Fixing One Bug in Our Programs, or Exotic Bugs in PVS-Studio and...
The Price of Fixing One Bug in Our Programs, or Exotic Bugs in PVS-Studio and...The Price of Fixing One Bug in Our Programs, or Exotic Bugs in PVS-Studio and...
The Price of Fixing One Bug in Our Programs, or Exotic Bugs in PVS-Studio and...
 
What's the Difference Between Static Analysis and Compiler Warnings?
What's the Difference Between Static Analysis and Compiler Warnings?What's the Difference Between Static Analysis and Compiler Warnings?
What's the Difference Between Static Analysis and Compiler Warnings?
 
Checking PVS-Studio with Clang
Checking PVS-Studio with ClangChecking PVS-Studio with Clang
Checking PVS-Studio with Clang
 
Computer & Video Game Archive @MLibrary
Computer & Video Game Archive @MLibraryComputer & Video Game Archive @MLibrary
Computer & Video Game Archive @MLibrary
 
Comparison of static code analyzers: CppCat, Cppcheck, PVS-Studio and Visual ...
Comparison of static code analyzers: CppCat, Cppcheck, PVS-Studio and Visual ...Comparison of static code analyzers: CppCat, Cppcheck, PVS-Studio and Visual ...
Comparison of static code analyzers: CppCat, Cppcheck, PVS-Studio and Visual ...
 
PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...
PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...
PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...
 
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ BuilderA Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
 
You can now use PVS-Studio with Visual Studio absent; just give it the prepro...
You can now use PVS-Studio with Visual Studio absent; just give it the prepro...You can now use PVS-Studio with Visual Studio absent; just give it the prepro...
You can now use PVS-Studio with Visual Studio absent; just give it the prepro...
 
A Long-Awaited Check of Unreal Engine 4
A Long-Awaited Check of Unreal Engine 4A Long-Awaited Check of Unreal Engine 4
A Long-Awaited Check of Unreal Engine 4
 
StdAfx.h for Novices
StdAfx.h for NovicesStdAfx.h for Novices
StdAfx.h for Novices
 
Tesseract. Recognizing Errors in Recognition Software
Tesseract. Recognizing Errors in Recognition SoftwareTesseract. Recognizing Errors in Recognition Software
Tesseract. Recognizing Errors in Recognition Software
 
Self Tester
Self TesterSelf Tester
Self Tester
 
Rwth Aachen
Rwth AachenRwth Aachen
Rwth Aachen
 
Personalised Technology Stimulates Innovation in the Workplace
Personalised Technology Stimulates Innovation in the WorkplacePersonalised Technology Stimulates Innovation in the Workplace
Personalised Technology Stimulates Innovation in the Workplace
 
Magnificence
MagnificenceMagnificence
Magnificence
 

Ähnlich wie Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by examples of errors detected in five open source projects

PVS-Studio Meets Octave
PVS-Studio Meets Octave PVS-Studio Meets Octave
PVS-Studio Meets Octave PVS-Studio
 
I want to sell a PVS-Studio license to the Intel company
I want to sell a PVS-Studio license to the Intel companyI want to sell a PVS-Studio license to the Intel company
I want to sell a PVS-Studio license to the Intel companyPVS-Studio
 
Analyzing the Dolphin-emu project
Analyzing the Dolphin-emu projectAnalyzing the Dolphin-emu project
Analyzing the Dolphin-emu projectPVS-Studio
 
CppCat Static Analyzer Review
CppCat Static Analyzer ReviewCppCat Static Analyzer Review
CppCat Static Analyzer ReviewAndrey Karpov
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codeAndrey Karpov
 
The Unicorn's Travel to the Microcosm
The Unicorn's Travel to the MicrocosmThe Unicorn's Travel to the Microcosm
The Unicorn's Travel to the MicrocosmAndrey Karpov
 
Checking the Code of LDAP-Server ReOpenLDAP on Our Readers' Request
Checking the Code of LDAP-Server ReOpenLDAP on Our Readers' RequestChecking the Code of LDAP-Server ReOpenLDAP on Our Readers' Request
Checking the Code of LDAP-Server ReOpenLDAP on Our Readers' RequestPVS-Studio
 
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...PVS-Studio
 
Intel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correctionIntel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correctionAndrey Karpov
 
Intel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correctionIntel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correctionPVS-Studio
 
Checking WinMerge with PVS-Studio for the second time
Checking WinMerge with PVS-Studio for the second timeChecking WinMerge with PVS-Studio for the second time
Checking WinMerge with PVS-Studio for the second timePVS-Studio
 
How to make fewer errors at the stage of code writing. Part N4.
How to make fewer errors at the stage of code writing. Part N4.How to make fewer errors at the stage of code writing. Part N4.
How to make fewer errors at the stage of code writing. Part N4.PVS-Studio
 
Date Processing Attracts Bugs or 77 Defects in Qt 6
Date Processing Attracts Bugs or 77 Defects in Qt 6Date Processing Attracts Bugs or 77 Defects in Qt 6
Date Processing Attracts Bugs or 77 Defects in Qt 6Andrey Karpov
 
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source Code
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source CodeA Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source Code
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source CodePVS-Studio
 
PVS-Studio vs Clang
PVS-Studio vs ClangPVS-Studio vs Clang
PVS-Studio vs ClangPVS-Studio
 

Ähnlich wie Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by examples of errors detected in five open source projects (15)

PVS-Studio Meets Octave
PVS-Studio Meets Octave PVS-Studio Meets Octave
PVS-Studio Meets Octave
 
I want to sell a PVS-Studio license to the Intel company
I want to sell a PVS-Studio license to the Intel companyI want to sell a PVS-Studio license to the Intel company
I want to sell a PVS-Studio license to the Intel company
 
Analyzing the Dolphin-emu project
Analyzing the Dolphin-emu projectAnalyzing the Dolphin-emu project
Analyzing the Dolphin-emu project
 
CppCat Static Analyzer Review
CppCat Static Analyzer ReviewCppCat Static Analyzer Review
CppCat Static Analyzer Review
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's code
 
The Unicorn's Travel to the Microcosm
The Unicorn's Travel to the MicrocosmThe Unicorn's Travel to the Microcosm
The Unicorn's Travel to the Microcosm
 
Checking the Code of LDAP-Server ReOpenLDAP on Our Readers' Request
Checking the Code of LDAP-Server ReOpenLDAP on Our Readers' RequestChecking the Code of LDAP-Server ReOpenLDAP on Our Readers' Request
Checking the Code of LDAP-Server ReOpenLDAP on Our Readers' Request
 
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
 
Intel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correctionIntel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correction
 
Intel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correctionIntel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correction
 
Checking WinMerge with PVS-Studio for the second time
Checking WinMerge with PVS-Studio for the second timeChecking WinMerge with PVS-Studio for the second time
Checking WinMerge with PVS-Studio for the second time
 
How to make fewer errors at the stage of code writing. Part N4.
How to make fewer errors at the stage of code writing. Part N4.How to make fewer errors at the stage of code writing. Part N4.
How to make fewer errors at the stage of code writing. Part N4.
 
Date Processing Attracts Bugs or 77 Defects in Qt 6
Date Processing Attracts Bugs or 77 Defects in Qt 6Date Processing Attracts Bugs or 77 Defects in Qt 6
Date Processing Attracts Bugs or 77 Defects in Qt 6
 
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source Code
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source CodeA Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source Code
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source Code
 
PVS-Studio vs Clang
PVS-Studio vs ClangPVS-Studio vs Clang
PVS-Studio vs Clang
 

Mehr von Andrey Karpov

60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста60 антипаттернов для С++ программиста
60 антипаттернов для С++ программистаAndrey Karpov
 
60 terrible tips for a C++ developer
60 terrible tips for a C++ developer60 terrible tips for a C++ developer
60 terrible tips for a C++ developerAndrey Karpov
 
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...Andrey Karpov
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesAndrey Karpov
 
PVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature OverviewPVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature OverviewAndrey Karpov
 
PVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибокPVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибокAndrey Karpov
 
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...Andrey Karpov
 
Best Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' MistakesBest Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' MistakesAndrey Karpov
 
Does static analysis need machine learning?
Does static analysis need machine learning?Does static analysis need machine learning?
Does static analysis need machine learning?Andrey Karpov
 
Typical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and JavaTypical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and JavaAndrey Karpov
 
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)Andrey Karpov
 
Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?Andrey Karpov
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerAndrey Karpov
 
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source SoftwareThe Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source SoftwareAndrey Karpov
 
Static Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal EngineStatic Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal EngineAndrey Karpov
 
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded SystemsSafety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded SystemsAndrey Karpov
 
The Great and Mighty C++
The Great and Mighty C++The Great and Mighty C++
The Great and Mighty C++Andrey Karpov
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?Andrey Karpov
 
Zero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for youZero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for youAndrey Karpov
 

Mehr von Andrey Karpov (20)

60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста
 
60 terrible tips for a C++ developer
60 terrible tips for a C++ developer60 terrible tips for a C++ developer
60 terrible tips for a C++ developer
 
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error Examples
 
PVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature OverviewPVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature Overview
 
PVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибокPVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибок
 
PVS-Studio в 2021
PVS-Studio в 2021PVS-Studio в 2021
PVS-Studio в 2021
 
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
 
Best Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' MistakesBest Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' Mistakes
 
Does static analysis need machine learning?
Does static analysis need machine learning?Does static analysis need machine learning?
Does static analysis need machine learning?
 
Typical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and JavaTypical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and Java
 
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
 
Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
 
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source SoftwareThe Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
 
Static Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal EngineStatic Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal Engine
 
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded SystemsSafety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
 
The Great and Mighty C++
The Great and Mighty C++The Great and Mighty C++
The Great and Mighty C++
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?
 
Zero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for youZero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for you
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Kürzlich hochgeladen (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by examples of errors detected in five open source projects

  • 1. Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by examples of errors detected in five open source projects Authors: Evgeniy Ryzhkov Date: 20.04.2011 Abstract The article demonstrates errors detected with the static code analyzer integrated into Visual Studio 2010. The research was performed on five open source projects. The same projects were also checked with PVS-Studio. Results of comparing these two tools are presented at the end of the article. Introduction The article "Difficulties of comparing code analyzers, or don't forget about usability" [1] tells that it is not so easy to compare two tools as it may seem because the parameter of usability is also highly significant besides the technical characteristics proper. Still we cannot do without comparing tools by errors they can detect. Of course, there is no sense in just calculating the number of errors. So we decided to carry out a practical experiment of error detection in real projects. We checked five random open source projects with the static analyzer integrated into Visual Studio 2010 Premium. We looked through the whole message list and chose explicit errors. Then we made the same steps with PVS-Studio. Here is a list of projects which participated in the research: • eMule Plus; • Pixie; • VirtualDub; • WinMerge; • XUIFramework. Let's go! eMule Plus The total number of messages generated by the Visual Studio static analyzer is 237, 4 of them being real errors. The total number of messages generated by PVS-Studio is 68, 3 of them being real errors.
  • 2. Visual Studio: warning C6054: String 'szwThemeFile' might not be zero-terminated. c:emuleplusdialogmintraybtn.hpp 445 WCHAR szwThemeFile[MAX_PATH]; WCHAR szwThemeColor[256]; if (m_themeHelper.GetCurrentThemeName(szwThemeFile, ARRSIZE(szwThemeFile), szwThemeColor, ARRSIZE(szwThemeColor), NULL, 0) != S_OK) return NULL; WCHAR *p; if ((p = wcsrchr(szwThemeFile, L'')) == NULL) Indeed, a line may not end with 0, which will cause potential problems. But in this particular case, this error is not likely to reveal itself. Visual Studio: warning C6269: Possibly incorrect order of operations: dereference ignored. c:emulepluscustomautocomplete.cpp 277 PVS-Studio: V532 Consider inspecting the statement of '*pointer++' pattern. Probably meant: '(*pointer)++'. customautocomplete.cpp 277 if (pceltFetched != NULL) *pceltFetched++; The programmer here "is not good at" using the (*ptr)++ expression. Although this construct seems to be rather safe, still this error is widespread. Visual Studio: warning C6298: Argument '6': using a read-only string as a writable string argument. This will attempt to write into static read-only memory and cause random crashes. c:emuleplusfirewallopener.cpp 183
  • 3. HRESULT hr = pNSC->AddPortMapping( riPortRule.m_strRuleName.AllocSysString(), riPortRule.m_byProtocol, riPortRule.m_nPortNumber, riPortRule.m_nPortNumber, 0, L"127.0.0.1", ICSTT_IPADDRESS, &pNSPM); Although it is not an error, the analyzer-generated message is fair. In general, this is a problem of all the static analyzers. They produce absolutely correct messages but they are far not always real errors. Does it mean that such tools and messages are useless? No, it does not, because fixing even such warnings helps to increase an overall quality of code. Visual Studio: warning C6314: Incorrect order of operations: bitwise- or has higher precedence than the conditional-expression operator. Add parentheses to clarify intent. c:emuleplussearchlistctrl.cpp 659 PVS-Studio: V502 Perhaps the '?:' operator works in a different way than it was expected. The '?:' operator has a lower priority than the '|' operator. searchlistctrl.cpp 659 menuSearchFile.AppendMenu( MF_STRING | ((iSelectionMark != -1) && (dwSelectedCount > 0) && g_App.m_pServerConnect->IsConnected() && ((pCurServer = g_App.m_pServerConnect->GetCurrentServer())!= NULL)&& (pCurServer->GetTCPFlags() & SRV_TCPFLG_RELATEDSEARCH)) ? MF_ENABLED : MF_GRAYED, MP_SEARCHRELATED, GetResString(IDS_SEARCHRELATED)); Here (because of the construct's complexity) we have wrong priorities of operators. For how long it has been said... Who prevented the programmer from arranging this code in several separate expressions instead of writing everything in one line (as it was done in the original program)? No, programmers would always want to "write it smart". PVS-Studio: V519 The 'm_clrSample' object is assigned values twice successively. Perhaps this is a mistake. fontpreviewcombo.cpp 61
  • 4. CFontPreviewCombo::CFontPreviewCombo() { ... m_clrSample = GetSysColor(COLOR_WINDOWTEXT); m_clrSample = RGB(60,0,0); ... } Perhaps the developers wanted to see how the RGB(60,0,0) color would look and forgot to remove it. Pixie The total number of messages generated by the Visual Studio static analyzer is 18, 0 of them being real errors. The total number of messages generated by PVS-Studio is 65, 5 of them being real errors. PVS-Studio: V519 The 'numRays' object is assigned values twice successively. Perhaps this is a mistake. bundles.cpp 579 void CGatherBundle::post() { numRays = last; numRays = 0; last = 0; depth++; } Oh, how suspicious it is when numRays is first initialized by one value and then by another. Is it an error or not? Only the code's author knows exactly. But it alerts me! PVS-Studio: V501 There are identical sub-expressions to the left and to the right of the '|' operator: PARAMETER_DPDU | PARAMETER_DPDU quadrics.cpp 880 if (up & (PARAMETER_DPDU | PARAMETER_DPDU)) {
  • 5. There must be something else here. By the way, here you a general note on fixing errors detected by a static analyzer. While in some cases correction is obvious and anyone can fix an error, in some other cases only the author of the code can make out what exactly was intended there. It is on the question if one could create a tool that can correct errors "like in Word". PVS-Studio: V501 There are identical sub-expressions to the left and to the right of the '|' operator: SLC_VECTOR | SLC_VECTOR expression.cpp 2604 lock(N, getConversion(SLC_VECTOR | SLC_VECTOR,parameters[2])); SLC_VECTOR mentioned twice in such a context certainly signals an error. PVS-Studio: V505 The 'alloca' function is used inside the loop. This can quickly overflow stack. polygons.cpp 1120 inline void triangulatePolygon(...) { ... for (i=1;i<nloops;i++) { ... do { ... do { ... CTriVertex *snVertex = (CTriVertex *) alloca(2*sizeof(CTriVertex)); ... } while(dVertex != loops[0]); ... } while(sVertex != loops[i]); ... }
  • 6. ... } Having deep nesting, the alloca call might cause stack overflow. VirtualDub The total number of messages generated by the Visual Studio static analyzer is 24 messages, 0 of them being real errors. The total number of messages generated by PVS-Studio is 41, 2 of them being real errors. PVS-Studio: V547 Expression 'c < 0' is always false. Unsigned type value is never < 0. lexer.cpp 279 typedef unsigned short wint_t; wint_t lexgetescape() { wint_t c = lexgetc(); if (c < 0) fatal("Newline found in escape sequence"); ... } The code will never be called because the expression is always false. PVS-Studio: V557 Array overrun is possible. The '9' index is pointing beyond array bound. f_convolute.cpp 73 struct ConvoluteFilterData { long m[9]; long bias; void *dyna_func; DWORD dyna_size; DWORD dyna_old_protect;
  • 7. BOOL fClip; }; static unsigned long __fastcall do_conv( unsigned long *data, const ConvoluteFilterData *cfd, long sflags, long pit) { long rt0=cfd->m[9], gt0=cfd->m[9], bt0=cfd->m[9]; ... } A trivial array overflow. WinMerge The total number of messages generated by the Visual Studio static analyzer is 343, 3 of them being real errors. The total number of messages generated by PVS-Studio is 69, 12 of them being real errors. Visual Studio: warning C6313: Incorrect operator: zero-valued flag cannot be tested with bitwise-and. Use an equality test to check for zero-valued flags. c:winmergesrcbcmenu.cpp 1489 else if (nFlags&MF_STRING){ ASSERT(!(nFlags&MF_OWNERDRAW)); ModifyMenu(pos,nFlags,nID,mdata->GetString()); } Not very lucky condition. Of course, the programmer wanted to write something different, but it happened that way. Visual Studio: warning C6287: Redundant code: the left and right sub-expressions are identical. c:winmergesrceditlibccrystaleditview.cpp 1560
  • 8. PVS-Studio: V501 There are identical sub-expressions to the left and to the right of the '||' operator: c == '}' || c == '}' ccrystaleditview.cpp 1560 bool isclosebrace (TCHAR c) { return c == _T ('}') || c == _T ('}') || c == _T (']') || c == _T ('>'); } Not all the parentheses types are checked. Why? It is usual that "Copy-paste-technology" leads to errors. Visual Studio: warning C6287: Redundant code: the left and right sub-expressions are identical. c:winmergesrcmergedoc.cpp 1165 PVS-Studio: V501 There are identical sub-expressions to the left and to the right of the '||' operator. mergedoc.cpp 1165 if ((m_nBufferType[nBuffer] == BUFFER_UNNAMED) || (m_nBufferType[nBuffer] == BUFFER_UNNAMED)) nSaveErrorCode = SAVE_NO_FILENAME; Another unlucky condition and again it seems to be the copy-paste's fault. PVS-Studio: V551 The code under this 'case' label is unreachable. The value range of signed char type: [-128, 127]. ccrystaltextview.cpp 1646 TCHAR ch = strText[i];
  • 9. switch (ch) { case 0xB7: case 0xBB: strHTML += ch; strHTML += _T("<wbr>"); bLastCharSpace = FALSE; nNonbreakChars = 0; break; And here we have a sample of code which will never be used. Everything seems alright, case is written and all, but it will never get control because the value range is too narrow. TCHAR in this case is the char type. PVS-Studio: V524 It is odd that the body of 'IsValidTextPosX' function is fully equivalent to the body of 'IsValidTextPos' function (ccrystaltextview.cpp, line 3700). ccrystaltextview.cpp 3707 bool CCrystalTextView::IsValidTextPos (const CPoint &point) { return GetLineCount () > 0 && m_nTopLine >= 0 && m_nOffsetChar >= 0 && point.y >= 0 && point.y < GetLineCount () && point.x >= 0 && point.x <= GetLineLength (point.y); } bool CCrystalTextView::IsValidTextPosX (const CPoint &point) { return GetLineCount () > 0 && m_nTopLine >= 0 && m_nOffsetChar >= 0 && point.y >= 0 && point.y < GetLineCount () && point.x >= 0 && point.x <= GetLineLength (point.y);
  • 10. } bool CCrystalTextView::IsValidTextPosY (const CPoint &point) { return GetLineCount () > 0 && m_nTopLine >= 0 && m_nOffsetChar >= 0 && point.y >= 0 && point.y < GetLineCount (); } These are very similar functions... The developers copy-pasted again and again and forgot to fix the result. The IsValidTextPosX() function performs an excess check. PVS-Studio: V563 It is possible that this 'else' branch must apply to the previous 'if' statement. bcmenu.cpp 1852 if(IsLunaMenuStyle()) if(!xp_space_accelerators)return; else if(!original_space_accelerators)return; Who can look at the code and say exactly to what if else refers? Was it the thing the programmer wanted to do? Are you sure? PVS-Studio: V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. diffwrapper.cpp 956 enum output_style {} ... enum DiffOutputType m_outputStyle; switch (m_options.m_outputStyle) {
  • 11. case OUTPUT_CONTEXT: enum and switch types were a bit mixed up. But it's alright, isn't it? PVS-Studio: V530 The return value of function 'empty' is required to be utilized. diractions.cpp 1307 void CDirView::GetItemFileNames(int sel, String& strLeft, String& strRight) const { UINT_PTR diffpos = GetItemKey(sel); if (diffpos == (UINT_PTR)SPECIAL_ITEM_POS) { strLeft.empty(); strRight.empty(); The case when empty() does not empty. This is an example of an extremely wrong name for a method. PVS-Studio: V524 It is odd that the body of 'OnUpdateLastdiff' function is fully equivalent to the body of 'OnUpdateFirstdiff' function (DirView.cpp, line 2189). dirview.cpp 2220 void CDirView::OnUpdateLastdiff(CCmdUI* pCmdUI) { int firstDiff = GetFirstDifferentItem(); if (firstDiff > -1) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); } void CDirView::OnUpdateFirstdiff(CCmdUI* pCmdUI)
  • 12. { int firstDiff = GetFirstDifferentItem(); if (firstDiff > -1) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); } Two more very similar functions... PVS-Studio: V501 There are identical sub-expressions 'pView1->GetTextBufferEol (line)' to the left and to the right of the '!=' operator. mergedoclinediffs.cpp 216 if (pView1->GetTextBufferEol(line) != pView1->GetTextBufferEol(line)) { Either this or that... Or not? Perhaps there must be pView2 here. PVS-Studio: V530 The return value of function 'empty' is required to be utilized. varprop.cpp 133 void VariantValue::Clear() { m_vtype = VT_NULL; m_bvalue = false; m_ivalue = 0; m_fvalue = 0; m_svalue.empty(); m_tvalue = 0; }
  • 13. Again empty() does not empty the string at all. PVS-Studio: V510 The 'Format' function is not expected to receive class-type variable as 'N' actual argument". PropShel 105 String GetSysError(int nerr); ... CString msg; msg.Format( _T("Failed to open registry key HKCU/%s:nt%d : %s"), f_RegDir, retVal, GetSysError(retVal) ); When various emergencies occur, WinMerge will try to inform the user about errors but in some cases it will fail. At first sight everything looks OK but actually the "String" type is just "std::wstring". Therefore we will print rubbish at best or get an Access Violation error at worst. The correct code must have a call of c_str(). PVS-Studio: V534 It is likely that a wrong variable is being compared inside the 'for' operator. Consider reviewing 'i'." BinTrans.cpp 357 // Get length of translated array of bytes from text. int Text2BinTranslator::iLengthOfTransToBin( char* src, int srclen ) { ... for (k=i; i<srclen; k++) { if (src[k]=='>') break; } ...
  • 14. } The analyzer found a suspicious loop. This code is prone to Access Violation. The loop must go on until it finds the '>' character or a string with the length of 'srclen' characters comes to an end. But the programmer by accident used the 'k' variable instead of 'i' for comparison. If the '>' character is not found, everything will be sad. XUIFramework The total number of messages generated by the Visual Studio static analyzer is 93, 2 of them being real errors. The total number of messages generated by PVS-Studio is 30, 5 of them being real errors. Visual Studio: warning C6269: Possibly incorrect order of operations: dereference ignored c:xui-gui frameworkwidgetscstatichtmlppdrawmanager.cpp 298 PVS-Studio: V532 Consider inspecting the statement of '*pointer++' pattern. Probably meant: '(*pointer)++'. ppdrawmanager.cpp 298 for (DWORD pixel = 0; pixel < dwWidth * dwHeight; pixel++, *pBits++) Again the programmer is not good at using *ptr++. As I have said above, this is a widespread error. Visual Studio: warning C6283: 'pBuffer' is allocated with array new[], but deleted with scalar delete. c:xui-gui frameworkwidgetscxstaticcxstatic.cpp 544 BYTE* pBuffer = new BYTE [ nBufferLen ]; ... delete pBuffer; The programmer confuses delete and delete[]. This causes issues which may occur and may not. But you should not do so anyway. PVS-Studio: V519 The 'm_xSt' object is assigned values twice
  • 15. successively. Perhaps this is a mistake. resizedlg.cpp 244 m_xSt = CST_RESIZE; m_xSt = CST_RESIZE; Judging by the code, there must be m_ySt here. But we cannot keep from using copy-paste again and again, right? V531 It is odd that a sizeof() operator is multiplied by sizeof(). pphtmldrawer.cpp 258 DWORD dwLen = ::LoadString(hInstDll, dwID, szTemp, (sizeof(szTemp) * sizeof(TCHAR))); There must be sizeof(szTemp) / sizeof(TCHAR) . PVS-Studio: V556 The values of different enum types are compared: enuHAlign == Center. cxstatic.cpp 151 if (enuHAlign == Center) There must be enuHAlign == Midle. There is also if in the code nearby (enuVAlign == Middle) though it must be Center. Confusion with enum, in short. PVS-Studio: V501 There are identical sub-expressions to the left and to the right of the '||' operator. resizedlg.cpp 157 HDWP CItemCtrl::OnSize(...) { ... if (m_styTop == CST_ZOOM || m_styTop == CST_ZOOM || m_styBottom == CST_DELTA_ZOOM ||
  • 16. m_styBottom == CST_DELTA_ZOOM) ... } Perhaps the code must look this way: HDWP CItemCtrl::OnSize(...) { ... if (m_styTop == CST_ZOOM || m_styTop == CST_DELTA_ZOOM || m_styBottom == CST_ZOOM || m_styBottom == CST_DELTA_ZOOM) ... } Comparison results We do not draw any certain conclusions. One of the tools was better in some projects and the other tool was better in others. References 1. Andrey Karpov, Evgeniy Ryzhkov. Difficulties of comparing code analyzers, or don't forget about usability. http://www.viva64.com/en/a/0071/.