SlideShare a Scribd company logo
1 of 6
Download to read offline
Analysis of the Ultimate Toolbox project
Author: Andrey Karpov

Date: 23.12.2010

While testing the general analyzer included into PVS-Studio 4.00, we checked several open-source
projects from the CodeProject site. One of those was Ultimate ToolBox.

We found some errors in the code of the Ultimate Toolbox project and would like to describe them
further in this article. For each case, we will give the diagnostic message generated by the analyzer,
corresponding file and line number. We will also give the code fragment containing a particular error
and a brief error description. To study the samples thoroughly, you may visit the resources by the links
given in the text.



1. Condition error

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);

    }

    ...

}

The V501 warning points to a condition error. It is most likely that there must be a condition comparing
left and right after the '&&' operator.

A similar error can also be found here:

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



2. Condition which is always true.
V547 Expression 'lpDrawItemStruct -> itemID >= 0' is always true. Unsigned type value is always >= 0. UT
oxautolistbox.cpp 56

void COXAutoListBox::DrawItem(...)

{

    ...

    if (lpDrawItemStruct->itemID>=0)

    {

        ...

    }

    ...

}

The "lpDrawItemStruct->itemID>=0" condition always holds because the itemID member has the UINT
type. Such errors are described in detail in documentation (V547). The code must have looked this way:

if (lpDrawItemStruct->itemID != (UINT)(-1))

{

    ...

}



3. Condition which is always false.

V547 Expression 'lpms -> itemID < 0' is always false. Unsigned type value is never < 0. UT
oxcoolcombobox.cpp 476

void COXCoolComboBox::MeasureItem(...)

{

    if(lpms->itemID<0)

        lpms->itemHeight=m_nDefaultFontHeight+1;

    else

        lpms->itemHeight=

          m_nDefaultFontHeightSansLeading+1;

}
The V547 warning tells us that the code "lpms->itemHeight=m_nDefaultFontHeight+1;" will be always
executed. Like in the previous case, it is caused by the fact that the itemID member has the unsigned
type UINT.



4. Inefficient code

V801 Decreased performance. It is better to redefine the first function argument as a reference.
Consider replacing 'const .. mi' with 'const .. &mi'. UT oxdllmanager.h 123

BOOL operator==(const _tagMODULEINFO mi) const

{

 return ((hModule==mi.hModule)&

    (sModuleFileName.CompareNoCase(mi.sModuleFileName)==0));

}

This code does not contain an error, but we may make it more efficient. There is no need in creating a
copy of the _tagMODULEINFO structure each time the '==' operator is called. The V801 message tells us
that we may replace "const _tagMODULEINFO mi" with "const _tagMODULEINFO &mi".



5. Condition error

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))

    ...

}

It is most likely that the programmer intended to write some other expression instead of the
"dwDockStyle == dwDockStyle" expression.



6. Handling 'char' as 'unsigned char'
Two warnings at once were given for one line:

V547 Expression 'chNewChar >= 128' is always false. The value range of signed char type: [-128, 127].
UT oxmaskededit.cpp 81

V547 Expression 'chNewChar <= 255' is always true. The value range of signed char type: [-128, 127]. UT
oxmaskededit.cpp 81

BOOL CMaskData::IsValidInput(TCHAR chNewChar)

{

    ...

    if((chNewChar >= 128) && (chNewChar <= 255))

      bIsValidInput=TRUE ;

    ...

}

This condition is meaningless since the chNewChar variable's value range is [-128..127]. It means that
the condition will never hold.



7. Logic error

V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error
presence. UT oxprocess.h 583

inline COXProcessIterator& operator+(int nOffset)

{

    if(nOffset>0)

      Next(nOffset);

    else if(nOffset>0)

      Prev(-nOffset);

    return *this;

}

The V517 warning points to an error in program's logic. The "Prev(-nOffset);" branch will never be
executed. The correct code must look as follows:

inline COXProcessIterator& operator+(int nOffset)

{

    if(nOffset>0)
Next(nOffset);

    else if(nOffset<0)

      Prev(-nOffset);

    return *this;

}

There are similar errors in other program's fragments:

V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error
presence. UT oxprocess.h 596

V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error
presence. UT oxprocess.h 610

V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error
presence. UT oxprocess.h 624



8. Condition which is always false.

V547 Expression 'm_nCurrentIndex - nOffset < 0' is always false. Unsigned type value is never < 0. UT
oxprocess.cpp 594

int m_nCurrentIndex;

...

BOOL COXProcessIterator::Prev(UINT nOffset)

{

    ...

    if(m_nCurrentIndex-nOffset<0)

      return FALSE;

    ...

}

Since the "m_nCurrentIndex-nOffset" expression has the unsigned type, it will never be below 0.



9. Error ASSERT()

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);

    ...

}

There must be this code:

ASSERT(m_totalDev.cx>=0 && m_totalDev.cy>=0);

There is also a similar error here:

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

More Related Content

What's hot

What's hot (20)

A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
A look into the sanitizer family (ASAN & UBSAN) by Akul PillaiA look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
 
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
 
Checking Notepad++: five years later
Checking Notepad++: five years laterChecking Notepad++: five years later
Checking Notepad++: five years later
 
Lab
LabLab
Lab
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
 
Exploiting vectorization with ISPC
Exploiting vectorization with ISPCExploiting vectorization with ISPC
Exploiting vectorization with ISPC
 
PVS-Studio is there to help CERN: analysis of Geant4 project
PVS-Studio is there to help CERN: analysis of Geant4 projectPVS-Studio is there to help CERN: analysis of Geant4 project
PVS-Studio is there to help CERN: analysis of Geant4 project
 
Checking Oracle VM VirtualBox. Part 1
Checking Oracle VM VirtualBox. Part 1Checking Oracle VM VirtualBox. Part 1
Checking Oracle VM VirtualBox. Part 1
 
A few words about OpenSSL
A few words about OpenSSLA few words about OpenSSL
A few words about OpenSSL
 
A Slipshod Check of the Visual C++ 2013 Library (update 3)
A Slipshod Check of the Visual C++ 2013 Library (update 3)A Slipshod Check of the Visual C++ 2013 Library (update 3)
A Slipshod Check of the Visual C++ 2013 Library (update 3)
 
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
 
Checking Oracle VM VirtualBox. Part 2
Checking Oracle VM VirtualBox. Part 2Checking Oracle VM VirtualBox. Part 2
Checking Oracle VM VirtualBox. Part 2
 
Reanalyzing the Notepad++ project
Reanalyzing the Notepad++ projectReanalyzing the Notepad++ project
Reanalyzing the Notepad++ project
 
AnyObject – 自分が見落としていた、基本の話
AnyObject – 自分が見落としていた、基本の話AnyObject – 自分が見落としていた、基本の話
AnyObject – 自分が見落としていた、基本の話
 
Конверсия управляемых языков в неуправляемые
Конверсия управляемых языков в неуправляемыеКонверсия управляемых языков в неуправляемые
Конверсия управляемых языков в неуправляемые
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
 
Explanations to the article on Copy-Paste
Explanations to the article on Copy-PasteExplanations to the article on Copy-Paste
Explanations to the article on Copy-Paste
 
Flashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas MacFlashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas Mac
 
Critical errors in CryEngine V code
Critical errors in CryEngine V codeCritical errors in CryEngine V code
Critical errors in CryEngine V code
 
Lesson 24. Phantom errors
Lesson 24. Phantom errorsLesson 24. Phantom errors
Lesson 24. Phantom errors
 

Viewers also liked

Viewers also liked (20)

An eternal question of timing
An eternal question of timingAn eternal question of timing
An eternal question of timing
 
Safety of 64-bit code
Safety of 64-bit codeSafety of 64-bit code
Safety of 64-bit code
 
Development of resource-intensive applications in Visual C++
Development of resource-intensive applications in Visual C++Development of resource-intensive applications in Visual C++
Development of resource-intensive applications in Visual C++
 
Lesson 1. What 64-bit systems are
Lesson 1. What 64-bit systems areLesson 1. What 64-bit systems are
Lesson 1. What 64-bit systems are
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
Lesson 10. Pattern 2. Functions with variable number of arguments
Lesson 10. Pattern 2. Functions with variable number of argumentsLesson 10. Pattern 2. Functions with variable number of arguments
Lesson 10. Pattern 2. Functions with variable number of arguments
 
Lesson 14. Pattern 6. Changing an array's type
Lesson 14. Pattern 6. Changing an array's typeLesson 14. Pattern 6. Changing an array's type
Lesson 14. Pattern 6. Changing an array's type
 
The reasons why 64-bit programs require more stack memory
The reasons why 64-bit programs require more stack memoryThe reasons why 64-bit programs require more stack memory
The reasons why 64-bit programs require more stack memory
 
Static code analysis and the new language standard C++0x
Static code analysis and the new language standard C++0xStatic code analysis and the new language standard C++0x
Static code analysis and the new language standard C++0x
 
Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?
 
Lesson 9. Pattern 1. Magic numbers
Lesson 9. Pattern 1. Magic numbersLesson 9. Pattern 1. Magic numbers
Lesson 9. Pattern 1. Magic numbers
 
Lesson 26. Optimization of 64-bit programs
Lesson 26. Optimization of 64-bit programsLesson 26. Optimization of 64-bit programs
Lesson 26. Optimization of 64-bit programs
 
Driver Development for Windows 64-bit
Driver Development for Windows 64-bitDriver Development for Windows 64-bit
Driver Development for Windows 64-bit
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
 
Comparison of analyzers' diagnostic possibilities at checking 64-bit code
Comparison of analyzers' diagnostic possibilities at checking 64-bit codeComparison of analyzers' diagnostic possibilities at checking 64-bit code
Comparison of analyzers' diagnostic possibilities at checking 64-bit code
 
Brief description of the VivaCore code analysis library
Brief description of the VivaCore code analysis libraryBrief description of the VivaCore code analysis library
Brief description of the VivaCore code analysis library
 
Lesson 23. Pattern 15. Growth of structures' sizes
Lesson 23. Pattern 15. Growth of structures' sizesLesson 23. Pattern 15. Growth of structures' sizes
Lesson 23. Pattern 15. Growth of structures' sizes
 
The essence of the VivaCore code analysis library
The essence of the VivaCore code analysis libraryThe essence of the VivaCore code analysis library
The essence of the VivaCore code analysis library
 
20 issues of porting C++ code on the 64-bit platform
20 issues of porting C++ code on the 64-bit platform20 issues of porting C++ code on the 64-bit platform
20 issues of porting C++ code on the 64-bit platform
 
32 OpenMP Traps For C++ Developers
32 OpenMP Traps For C++ Developers32 OpenMP Traps For C++ Developers
32 OpenMP Traps For C++ Developers
 

Similar to Analysis of the Ultimate Toolbox project

Similar to Analysis of the Ultimate Toolbox project (20)

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 for Linux Went on a Tour Around Disney
PVS-Studio for Linux Went on a Tour Around DisneyPVS-Studio for Linux Went on a Tour Around Disney
PVS-Studio for Linux Went on a Tour Around Disney
 
Checking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioChecking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-Studio
 
Checking the Source SDK Project
Checking the Source SDK ProjectChecking the Source SDK Project
Checking the Source SDK Project
 
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
 
The CppCat Analyzer Checks TortoiseGit
The CppCat Analyzer Checks TortoiseGitThe CppCat Analyzer Checks TortoiseGit
The CppCat Analyzer Checks TortoiseGit
 
Spring RTS Engine Checkup
Spring RTS Engine CheckupSpring RTS Engine Checkup
Spring RTS Engine Checkup
 
Headache from using mathematical software
Headache from using mathematical softwareHeadache from using mathematical software
Headache from using mathematical software
 
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
 
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
 
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...
 
Tesseract. Recognizing Errors in Recognition Software
Tesseract. Recognizing Errors in Recognition SoftwareTesseract. Recognizing Errors in Recognition Software
Tesseract. Recognizing Errors in Recognition Software
 
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
 
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
 
Analyzing Firebird 3.0
Analyzing Firebird 3.0Analyzing Firebird 3.0
Analyzing Firebird 3.0
 
Analyzing Firebird 3.0
Analyzing Firebird 3.0Analyzing Firebird 3.0
Analyzing Firebird 3.0
 
Checking the code of Valgrind dynamic analyzer by a static analyzer
Checking the code of Valgrind dynamic analyzer by a static analyzerChecking the code of Valgrind dynamic analyzer by a static analyzer
Checking the code of Valgrind dynamic analyzer by a static analyzer
 
Top 10 C# projects errors found in 2016
Top 10 C# projects errors found in 2016Top 10 C# projects errors found in 2016
Top 10 C# projects errors found in 2016
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Analysis of the Ultimate Toolbox project

  • 1. Analysis of the Ultimate Toolbox project Author: Andrey Karpov Date: 23.12.2010 While testing the general analyzer included into PVS-Studio 4.00, we checked several open-source projects from the CodeProject site. One of those was Ultimate ToolBox. We found some errors in the code of the Ultimate Toolbox project and would like to describe them further in this article. For each case, we will give the diagnostic message generated by the analyzer, corresponding file and line number. We will also give the code fragment containing a particular error and a brief error description. To study the samples thoroughly, you may visit the resources by the links given in the text. 1. Condition error 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); } ... } The V501 warning points to a condition error. It is most likely that there must be a condition comparing left and right after the '&&' operator. A similar error can also be found here: V501 There are identical sub-expressions to the left and to the right of the '&&' operator. UT oxtabclientwnd.cpp 184 2. Condition which is always true.
  • 2. V547 Expression 'lpDrawItemStruct -> itemID >= 0' is always true. Unsigned type value is always >= 0. UT oxautolistbox.cpp 56 void COXAutoListBox::DrawItem(...) { ... if (lpDrawItemStruct->itemID>=0) { ... } ... } The "lpDrawItemStruct->itemID>=0" condition always holds because the itemID member has the UINT type. Such errors are described in detail in documentation (V547). The code must have looked this way: if (lpDrawItemStruct->itemID != (UINT)(-1)) { ... } 3. Condition which is always false. V547 Expression 'lpms -> itemID < 0' is always false. Unsigned type value is never < 0. UT oxcoolcombobox.cpp 476 void COXCoolComboBox::MeasureItem(...) { if(lpms->itemID<0) lpms->itemHeight=m_nDefaultFontHeight+1; else lpms->itemHeight= m_nDefaultFontHeightSansLeading+1; }
  • 3. The V547 warning tells us that the code "lpms->itemHeight=m_nDefaultFontHeight+1;" will be always executed. Like in the previous case, it is caused by the fact that the itemID member has the unsigned type UINT. 4. Inefficient code V801 Decreased performance. It is better to redefine the first function argument as a reference. Consider replacing 'const .. mi' with 'const .. &mi'. UT oxdllmanager.h 123 BOOL operator==(const _tagMODULEINFO mi) const { return ((hModule==mi.hModule)& (sModuleFileName.CompareNoCase(mi.sModuleFileName)==0)); } This code does not contain an error, but we may make it more efficient. There is no need in creating a copy of the _tagMODULEINFO structure each time the '==' operator is called. The V801 message tells us that we may replace "const _tagMODULEINFO mi" with "const _tagMODULEINFO &mi". 5. Condition error 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)) ... } It is most likely that the programmer intended to write some other expression instead of the "dwDockStyle == dwDockStyle" expression. 6. Handling 'char' as 'unsigned char'
  • 4. Two warnings at once were given for one line: V547 Expression 'chNewChar >= 128' is always false. The value range of signed char type: [-128, 127]. UT oxmaskededit.cpp 81 V547 Expression 'chNewChar <= 255' is always true. The value range of signed char type: [-128, 127]. UT oxmaskededit.cpp 81 BOOL CMaskData::IsValidInput(TCHAR chNewChar) { ... if((chNewChar >= 128) && (chNewChar <= 255)) bIsValidInput=TRUE ; ... } This condition is meaningless since the chNewChar variable's value range is [-128..127]. It means that the condition will never hold. 7. Logic error V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. UT oxprocess.h 583 inline COXProcessIterator& operator+(int nOffset) { if(nOffset>0) Next(nOffset); else if(nOffset>0) Prev(-nOffset); return *this; } The V517 warning points to an error in program's logic. The "Prev(-nOffset);" branch will never be executed. The correct code must look as follows: inline COXProcessIterator& operator+(int nOffset) { if(nOffset>0)
  • 5. Next(nOffset); else if(nOffset<0) Prev(-nOffset); return *this; } There are similar errors in other program's fragments: V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. UT oxprocess.h 596 V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. UT oxprocess.h 610 V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. UT oxprocess.h 624 8. Condition which is always false. V547 Expression 'm_nCurrentIndex - nOffset < 0' is always false. Unsigned type value is never < 0. UT oxprocess.cpp 594 int m_nCurrentIndex; ... BOOL COXProcessIterator::Prev(UINT nOffset) { ... if(m_nCurrentIndex-nOffset<0) return FALSE; ... } Since the "m_nCurrentIndex-nOffset" expression has the unsigned type, it will never be below 0. 9. Error ASSERT() V501 There are identical sub-expressions to the left and to the right of the '&&' operator. UT oxscrollwnd.cpp 645 void COXScrollWnd::OnPrepareDC(...)
  • 6. { ... ASSERT(m_totalDev.cx>=0 && m_totalDev.cx>=0); ... } There must be this code: ASSERT(m_totalDev.cx>=0 && m_totalDev.cy>=0); There is also a similar error here: V501 There are identical sub-expressions to the left and to the right of the '&&' operator. UT oxzoomvw.cpp 179