SlideShare a Scribd company logo
PVS-Studio,
a solution for developers of modern
resource-intensive applications

OOO “Program Verification Systems” (Co Ltd)



            www.viva64.com
PVS-Studio Overview
          PVS-Studio is a static analyzer that
          detects errors in source code of C, C++,
          C++11, C++/CX applications.

          There are 3 sets of rules included into
          PVS-Studio:

           1. General-purpose diagnosis
           2. Diagnosis of 64-bit errors (Viva64)
           3. Diagnosis of parallel errors (VivaMP)
Examples of errors we detect
Priority of & and ! operations
      Return to Castle Wolfenstein – computer game, first
      person shooter, developed by id Software company. Game
      engine is available under GPL license.


       #define SVF_CASTAI      0x00000010

       if ( !ent->r.svFlags & SVF_CASTAI )


       if ( ! (ent->r.svFlags & SVF_CASTAI) )
Usage of && instead of &

                        Stickies – yellow sticky notes, just only on your
                        monitor.




#define REO_INPLACEACTIVE   (0x02000000L)
#define REO_OPEN            (0x04000000L)

if (reObj.dwFlags && REO_INPLACEACTIVE)
  m_pRichEditOle->InPlaceDeactivate();

if(reObj.dwFlags && REO_OPEN)
  hr = reObj.poleobj->Close(OLECLOSE_NOSAVE);
Undefined behavior
                          Miranda IM (Miranda Instant Messenger) –
                          instant messaging software for Microsoft
                          Windows.

while (*(n = ++s + strspn(s, EZXML_WS)) && *n != '>') {
Usage of `delete` for an array
                     Chromium – open source web browser developed by
                     Google. The development of Google Chrome browser is
                     based upon Chromium.


 auto_ptr<VARIANT> child_array(new VARIANT[child_count]);

You should not use auto_ptr with arrays. Only one element is destroyed inside
auto_ptr destructor:
~auto_ptr() {
  delete _Myptr;
}

For example you can use boost::scoped_array as an alternative.
Condition is always true

                                  WinDjView is fast and small app for viewing
                                  files of DjVu format.




inline bool IsValidChar(int c)
{
  return c == 0x9 || 0xA || c == 0xD || c >= 0x20 && c <= 0xD7FF
      || c >= 0xE000 && c <= 0xFFFD || c >= 0x10000 && c <= 0x10FFFF;
}
Code formatting differs from it’s own
                  logic
                                     Squirrel – interpreted programming
                                     language, which is developed to be used as
                                     a scripting language in real time
                                     applications such as computer games.



 if(pushval != 0)
    if(pushval) v->GetUp(-1) = t;
  else
    v->Pop(1);

v->Pop(1); - will never be reached
Incidental local variable declaration

           FCE Ultra – open source Nintendo Entertainment
           System console emulator

              int iNesSaveAs(char* name)
              {
                ...
                fp = fopen(name,"wb");
                int x = 0;
                if (!fp)
                  int x = 1;
                ...
              }
Using char as unsigned char
          // check each line for illegal utf8 sequences.
          // If one is found, we treat the file as ASCII,
          // otherwise we assume an UTF8 file.
          char * utf8CheckBuf = lineptr;
          while ((bUTF8)&&(*utf8CheckBuf))
          {
            if ((*utf8CheckBuf == 0xC0)||
                (*utf8CheckBuf == 0xC1)||
                (*utf8CheckBuf >= 0xF5))
            {
              bUTF8 = false;
              break;
            }

TortoiseSVN — client of Subversion revision control system,
implemented as Windows shell extension.
Incidental use of octal values
oCell._luminance = uint16(0.2220f*iPixel._red +
                          0.7067f*iPixel._blue +
                          0.0713f*iPixel._green);

....

oCell._luminance = 2220*iPixel._red +
                   7067*iPixel._blue +
                   0713*iPixel._green;




                eLynx Image Processing SDK and Lab
One variable is used for two loops
          Lugaru — first commercial game developed by
          Wolfire Games independent team.

          static int i,j,k,l,m;
          ...
          for(j=0; j<numrepeats; j++){
            ...
            for(i=0; i<num_joints; i++){
              ...
              for(j=0;j<num_joints;j++){
                if(joints[j].locked)freely=0;
              }
              ...
            }
            ...
          }
Array overrun

                      LAME – free app for MP3 audio encoding.




#define SBMAX_l      22
int l[1+SBMAX_l];

for (r0 = 0; r0 < 16; r0++) {
   ...
   for (r1 = 0; r1 < 8; r1++) {
     int a2 = gfc->scalefac_band.l[r0 + r1 + 2];
Priority of * and ++ operations
      eMule is a client for ED2K file sharing network.

      STDMETHODIMP CCustomAutoComplete::Next(...,
        ULONG *pceltFetched)
      {
        ...
        if (pceltFetched != NULL)
          *pceltFetched++;
        ...
      }

      (*pceltFetched)++;
Comparison mistake
                             WinMerge — free open source software intended for
                             the comparison and synchronization of files and
                             directories.



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

By reviewing the code close by, this should contain:
(m_nBufferType[0] == BUFFER_UNNAMED) ||
(m_nBufferType[1] == BUFFER_UNNAMED)
Forgotten array index
void lNormalizeVector_32f_P3IM(..., Ipp32s* mask, ...) {
  Ipp32s i;
  Ipp32f norm;

    for(i=0; i<len; i++) {
      if(mask<0) continue;
      ...
    }
}

if(mask[i]<0) continue;

             IPP Samples are samples demonstrating how to
             work with Intel Performance Primitives Library
             7.0.
Identical source code branches
                 Notepad++ - free text editor for Windows supporting
                 syntax highlight for a variety of programming languages.




if (!_isVertical)                    if (!_isVertical)
  Flags |= DT_BOTTOM;                   Flags |= DT_VCENTER;
else                                  else
  Flags |= DT_BOTTOM;                   Flags |= DT_BOTTOM;
Calling incorrect function with similar
                     name
What a beautiful comment. But it is sad that here we’re doing not what was
intended.
/** Deletes all previous field specifiers.
  * This should be used when dealing
  * with clients that send multiple NEP_PACKET_SPEC
  * messages, so only the last PacketSpec is taken
  * into account. */
int NEPContext::resetClientFieldSpecs(){
  this->fspecs.empty();
  return OP_SUCCESS;
} /* End of resetClientFieldSpecs() */

               Nmap Security Scanner – free utility intended for
               diverse customizable scanning of IP-networks with
               any number of objects and for identification of the
               statuses of the objects belonging to the network
               which is being scanned.
Dangerous ?: operator

                                Newton Game Dynamics – a well known physics
                                engine which allows for reliable and fast simulation
                                of environmental object’s physical behavior.




den = dgFloat32 (1.0e-24f) *
  (den > dgFloat32(0.0f)) ? dgFloat32(1.0f) : dgFloat32(-1.0f);

The priority of ?: is lower than that of multiplication operator *.
And so on, and so on…
if((t=(char *)realloc(
  next->name, strlen(name+1))))             FCE Ultra

if((t=(char *)realloc(
  next->name, strlen(name)+1)))



minX=max(0,minX+mcLeftStart-2);
minY=max(0,minY+mcTopStart-2);
maxX=min((int)width,maxX+mcRightEnd-1);
maxY=min((int)height,maxX+mcBottomEnd-1);

minX=max(0,minX+mcLeftStart-2);
minY=max(0,minY+mcTopStart-2);
maxX=min((int)width,maxX+mcRightEnd-1);
maxY=min((int)height,maxY+mcBottomEnd-1);
Low level memory management
                operations
ID_INLINE mat3_t::mat3_t( float src[3][3] )      Return to Castle
{
                                                   Wolfenstein
  memcpy( mat, src, sizeof( src ) );
}

ID_INLINE mat3_t::mat3_t( float (&src)[3][3] )
{
  memcpy( mat, src, sizeof( src ) );
}


itemInfo_t *itemInfo;
memset( itemInfo, 0, sizeof( &itemInfo ) );

memset( itemInfo, 0, sizeof( *itemInfo ) );
Low level memory management
                operations

                CxImage – open image processing library.




memset(tcmpt->stepsizes, 0,
    sizeof(tcmpt->numstepsizes * sizeof(uint_fast16_t)));

memset(tcmpt->stepsizes, 0,
  tcmpt->numstepsizes * sizeof(uint_fast16_t));
Low level memory management
                   operations

  A beautiful example of 64-bit error:

dgInt32 faceOffsetHitogram[256];
dgSubMesh* mainSegmenst[256];

memset (faceOffsetHitogram, 0, sizeof (faceOffsetHitogram));
memset (mainSegmenst, 0, sizeof (faceOffsetHitogram));


This code was duplicated but was not entirely corrected. As a result the
size of pointer will not be equal to the size of dgInt32 type on Win64 and
we will flush only a fraction of mainSegmenst array.
Low level memory management
               operations
#define CONT_MAP_MAX 50
int _iContMap[CONT_MAP_MAX];
...
memset(_iContMap, -1, CONT_MAP_MAX);

memset(_iContMap, -1, CONT_MAP_MAX * sizeof(int));
Low level memory management
          operations
       OGRE — open source Object-Oriented Graphics
       Rendering Engine written in C++.


       Real w, x, y, z;
       ...

       inline Quaternion(Real* valptr)
       {
         memcpy(&w, valptr, sizeof(Real)*4);
       }

        Yes, at present
         this is not a
           mistake.
           But it is a
          landmine!
And a whole lot of other errors in well
              known projects
•    WinMerge
•    Chromium, Return to Castle Wolfenstein, etc
•    Miranda IM
•    Intel IPP Samples
•    Fennec Media Project
•    Ultimate Toolbox
•    Loki
•    eMule Plus, Pixie, VirtualDub, WinMerge, XUIFramework
•    Chromium
•    Qt
•    Apache HTTP Server
•    TortoiseSVN

                       Here are the links to the articles containing descriptions of the errors:
                                                       http://www.viva64.com/en/pvs-studio/
Types of detectable errors
• copy-paste errors;
• Incorrect formatting strings (printf);
• buffer overflow;
• Incorrect utilization of STL, WinAPI;
• ...
• errors concerning the migration of 32-bit
  applications to 64-bit systems (Viva64);
• errors concerning the incorrect usage of
  OpenMP;
Integration
• Visual Studio 2012: C, C++, C++11,
  C++/CX (WinRT).
• Visual Studio 2010: C, C++, C++0x.
• Visual Studio 2008: C, C++.
• Visual Studio 2005: C, C++.
• Embarcadero RAD Studio XE3: C, C++, C++11.
• Embarcadero RAD Studio XE2: C, C++.
• MinGW: C, C++.
PVS-Studio Features
•   Incremental Analysis – verification of newly compiled files;
•   Verification of files which were recently modified several days ago;
•   Verification of files by their filenames from within the text file list;
•   continuous integration systems support;
•   version control systems integration;
•   ability to operate fro m command line interface;
•   «False Alarms» marking;
•   saving and loading of analysis results;
•   utilizing all available cores and processors;
•   interactive filters;
•   Russian and English online documentation;
•   Pdf documentation;
Integration with Visual Studio
    2005/2008/2010/2012
Integration with
Embarcadero RAD Studio XE2/XE3
Incremental Analysis – verification of newly
              compiled files
• you just work with Visual Studio as usual;
• compile by F7;
• the verification of newly compiled files will start in
  background automatically;
• At the end of verification the notification will appear,
  allowing you to inspect detected errors;
VCS and CI support
         (revision control, continuous integration)
• launching from command line:
 "C:Program Files (x86)PVS-Studiox64PVS-Studio.exe"
 --sln-file "C:UsersevgDocuments OmniSampleOmniSample (vs2008).sln"
 --plog-file "C:UsersevgDocumentsresult.plog"
 --vcinstalldir "C:Program Files (x86)Microsoft Visual Studio 9.0VC"
 --platform "x64"
 --configuration "Release”


• sending the results by mail:
 cmd.exe /c type result-log.plog.only_new_messages.txt

• commands for launching from CruiseControl.Net,
  Hudson, Microsoft TFS are readily available
Interactive filters
• filtering messages without restarting the
  analysis
• Filtering by errors’ code, by filenames
  (including masks), by messages’ text, by
  warning levels;
• displaying/hiding false alarms.
Integrated
    help
 reference

(description
   of the
  errors)
PVS-Studio Advantages
• Easy-to-download! You may download the PVS-Studio
  distribution package without registering and filling in
  any forms.
• Easy-to-try! The PVS-Studio program is implemented
  as a plug-in for Visual Studio and Embarcadero RAD
  Studio.
• Easy-to-buy! Unlike other code analyzers, we have
  simple pricing and licensing policy.
• Easy-to-support! It is the analyzer's developers who
  directly communicate with users, which enables you to
  quickly get answers to even complicated questions
  related to programming.
Pricing policy
• a license for a team of no more than five
  developers is €5250;
• prolongation for one year – 80% of base price;
• the site license for teams with 20+
  developers;
Information about company
OOO “Program Verification Systems” (Co Ltd)
 300027, Russia, Tula, Metallurgov 70-1-88.

www.viva64.com
support@viva64.com


Working time: 09:00 – 18:00 (GMT +3:00)

More Related Content

What's hot (20)

PDF
Checking Clang 11 with PVS-Studio
Andrey Karpov
 
PPTX
200 Open Source Projects Later: Source Code Static Analysis Experience
Andrey Karpov
 
PDF
Checking the Qt 5 Framework
Andrey Karpov
 
PDF
A fresh eye on Oracle VM VirtualBox
PVS-Studio
 
PPTX
PVS-Studio in 2019
Andrey Karpov
 
PDF
Linux version of PVS-Studio couldn't help checking CodeLite
PVS-Studio
 
PPTX
Static Code Analysis for Projects, Built on Unreal Engine
Andrey Karpov
 
PDF
Intel IPP Samples for Windows - error correction
Andrey Karpov
 
PDF
Intel IPP Samples for Windows - error correction
PVS-Studio
 
PDF
Intel IPP Samples for Windows - error correction
PVS-Studio
 
PDF
Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
Andrey Karpov
 
PDF
Top 10 bugs in C++ open source projects, checked in 2016
PVS-Studio
 
PDF
Better Code: Concurrency
Platonov Sergey
 
PDF
Heading for a Record: Chromium, the 5th Check
PVS-Studio
 
PDF
The Little Unicorn That Could
PVS-Studio
 
PDF
Critical errors in CryEngine V code
PVS-Studio
 
PDF
Joel Falcou, Boost.SIMD
Sergey Platonov
 
PDF
Reanalyzing the Notepad++ project
PVS-Studio
 
PDF
Waiting for the Linux-version: Checking the Code of Inkscape Graphics Editor
PVS-Studio
 
PDF
Checking Notepad++: five years later
PVS-Studio
 
Checking Clang 11 with PVS-Studio
Andrey Karpov
 
200 Open Source Projects Later: Source Code Static Analysis Experience
Andrey Karpov
 
Checking the Qt 5 Framework
Andrey Karpov
 
A fresh eye on Oracle VM VirtualBox
PVS-Studio
 
PVS-Studio in 2019
Andrey Karpov
 
Linux version of PVS-Studio couldn't help checking CodeLite
PVS-Studio
 
Static Code Analysis for Projects, Built on Unreal Engine
Andrey Karpov
 
Intel IPP Samples for Windows - error correction
Andrey Karpov
 
Intel IPP Samples for Windows - error correction
PVS-Studio
 
Intel IPP Samples for Windows - error correction
PVS-Studio
 
Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
Andrey Karpov
 
Top 10 bugs in C++ open source projects, checked in 2016
PVS-Studio
 
Better Code: Concurrency
Platonov Sergey
 
Heading for a Record: Chromium, the 5th Check
PVS-Studio
 
The Little Unicorn That Could
PVS-Studio
 
Critical errors in CryEngine V code
PVS-Studio
 
Joel Falcou, Boost.SIMD
Sergey Platonov
 
Reanalyzing the Notepad++ project
PVS-Studio
 
Waiting for the Linux-version: Checking the Code of Inkscape Graphics Editor
PVS-Studio
 
Checking Notepad++: five years later
PVS-Studio
 

Viewers also liked (6)

PPT
New Media 2009
Damo Ward
 
PPT
Epcal
fhseabrook
 
PPTX
Windows Phone Code Camp Montreal - An introduction to Windows Phone development
Frédéric Harper
 
PPTX
"The Business of Marketing You and Your Book"
Joanne Funch
 
PPTX
Social Networks and Online Travel Marketing
Themistocles Papadimopoulos
 
New Media 2009
Damo Ward
 
Epcal
fhseabrook
 
Windows Phone Code Camp Montreal - An introduction to Windows Phone development
Frédéric Harper
 
"The Business of Marketing You and Your Book"
Joanne Funch
 
Social Networks and Online Travel Marketing
Themistocles Papadimopoulos
 
Ad

Similar to PVS-Studio 5.00, a solution for developers of modern resource-intensive applications (20)

PPTX
PVS-Studio, a solution for resource intensive applications development
OOO "Program Verification Systems"
 
PPTX
Static analysis of C++ source code
PVS-Studio
 
PPTX
Static analysis of C++ source code
Andrey Karpov
 
KEY
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Vincenzo Iozzo
 
PPT
Georgy Nosenko - An introduction to the use SMT solvers for software security
DefconRussia
 
PDF
Beyond Breakpoints: A Tour of Dynamic Analysis
Fastly
 
PDF
JIT compilation for CPython
delimitry
 
PPTX
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
Positive Hack Days
 
PDF
Vectorization on x86: all you need to know
Roberto Agostino Vitillo
 
PDF
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
Teddy Hsiung
 
PDF
Windbg랑 친해지기
Ji Hun Kim
 
PDF
PVS-Studio for Linux Went on a Tour Around Disney
PVS-Studio
 
PDF
The following code is an implementation of the producer consumer pro.pdf
marketing413921
 
PDF
Checking the Source SDK Project
Andrey Karpov
 
PDF
Pascal script maxbox_ekon_14_2
Max Kleiner
 
PDF
Skiron - Experiments in CPU Design in D
Mithun Hunsur
 
PPTX
grsecurity and PaX
Kernel TLV
 
PDF
Tesseract. Recognizing Errors in Recognition Software
Andrey Karpov
 
PPTX
Track c-High speed transaction-based hw-sw coverification -eve
chiportal
 
PPTX
Building High-Performance Language Implementations With Low Effort
Stefan Marr
 
PVS-Studio, a solution for resource intensive applications development
OOO "Program Verification Systems"
 
Static analysis of C++ source code
PVS-Studio
 
Static analysis of C++ source code
Andrey Karpov
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Vincenzo Iozzo
 
Georgy Nosenko - An introduction to the use SMT solvers for software security
DefconRussia
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Fastly
 
JIT compilation for CPython
delimitry
 
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
Positive Hack Days
 
Vectorization on x86: all you need to know
Roberto Agostino Vitillo
 
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
Teddy Hsiung
 
Windbg랑 친해지기
Ji Hun Kim
 
PVS-Studio for Linux Went on a Tour Around Disney
PVS-Studio
 
The following code is an implementation of the producer consumer pro.pdf
marketing413921
 
Checking the Source SDK Project
Andrey Karpov
 
Pascal script maxbox_ekon_14_2
Max Kleiner
 
Skiron - Experiments in CPU Design in D
Mithun Hunsur
 
grsecurity and PaX
Kernel TLV
 
Tesseract. Recognizing Errors in Recognition Software
Andrey Karpov
 
Track c-High speed transaction-based hw-sw coverification -eve
chiportal
 
Building High-Performance Language Implementations With Low Effort
Stefan Marr
 
Ad

More from Andrey Karpov (20)

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

Recently uploaded (20)

PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 

PVS-Studio 5.00, a solution for developers of modern resource-intensive applications

  • 1. PVS-Studio, a solution for developers of modern resource-intensive applications OOO “Program Verification Systems” (Co Ltd) www.viva64.com
  • 2. PVS-Studio Overview PVS-Studio is a static analyzer that detects errors in source code of C, C++, C++11, C++/CX applications. There are 3 sets of rules included into PVS-Studio: 1. General-purpose diagnosis 2. Diagnosis of 64-bit errors (Viva64) 3. Diagnosis of parallel errors (VivaMP)
  • 3. Examples of errors we detect
  • 4. Priority of & and ! operations Return to Castle Wolfenstein – computer game, first person shooter, developed by id Software company. Game engine is available under GPL license. #define SVF_CASTAI 0x00000010 if ( !ent->r.svFlags & SVF_CASTAI ) if ( ! (ent->r.svFlags & SVF_CASTAI) )
  • 5. Usage of && instead of & Stickies – yellow sticky notes, just only on your monitor. #define REO_INPLACEACTIVE (0x02000000L) #define REO_OPEN (0x04000000L) if (reObj.dwFlags && REO_INPLACEACTIVE) m_pRichEditOle->InPlaceDeactivate(); if(reObj.dwFlags && REO_OPEN) hr = reObj.poleobj->Close(OLECLOSE_NOSAVE);
  • 6. Undefined behavior Miranda IM (Miranda Instant Messenger) – instant messaging software for Microsoft Windows. while (*(n = ++s + strspn(s, EZXML_WS)) && *n != '>') {
  • 7. Usage of `delete` for an array Chromium – open source web browser developed by Google. The development of Google Chrome browser is based upon Chromium. auto_ptr<VARIANT> child_array(new VARIANT[child_count]); You should not use auto_ptr with arrays. Only one element is destroyed inside auto_ptr destructor: ~auto_ptr() { delete _Myptr; } For example you can use boost::scoped_array as an alternative.
  • 8. Condition is always true WinDjView is fast and small app for viewing files of DjVu format. inline bool IsValidChar(int c) { return c == 0x9 || 0xA || c == 0xD || c >= 0x20 && c <= 0xD7FF || c >= 0xE000 && c <= 0xFFFD || c >= 0x10000 && c <= 0x10FFFF; }
  • 9. Code formatting differs from it’s own logic Squirrel – interpreted programming language, which is developed to be used as a scripting language in real time applications such as computer games. if(pushval != 0) if(pushval) v->GetUp(-1) = t; else v->Pop(1); v->Pop(1); - will never be reached
  • 10. Incidental local variable declaration FCE Ultra – open source Nintendo Entertainment System console emulator int iNesSaveAs(char* name) { ... fp = fopen(name,"wb"); int x = 0; if (!fp) int x = 1; ... }
  • 11. Using char as unsigned char // check each line for illegal utf8 sequences. // If one is found, we treat the file as ASCII, // otherwise we assume an UTF8 file. char * utf8CheckBuf = lineptr; while ((bUTF8)&&(*utf8CheckBuf)) { if ((*utf8CheckBuf == 0xC0)|| (*utf8CheckBuf == 0xC1)|| (*utf8CheckBuf >= 0xF5)) { bUTF8 = false; break; } TortoiseSVN — client of Subversion revision control system, implemented as Windows shell extension.
  • 12. Incidental use of octal values oCell._luminance = uint16(0.2220f*iPixel._red + 0.7067f*iPixel._blue + 0.0713f*iPixel._green); .... oCell._luminance = 2220*iPixel._red + 7067*iPixel._blue + 0713*iPixel._green; eLynx Image Processing SDK and Lab
  • 13. One variable is used for two loops Lugaru — first commercial game developed by Wolfire Games independent team. static int i,j,k,l,m; ... for(j=0; j<numrepeats; j++){ ... for(i=0; i<num_joints; i++){ ... for(j=0;j<num_joints;j++){ if(joints[j].locked)freely=0; } ... } ... }
  • 14. Array overrun LAME – free app for MP3 audio encoding. #define SBMAX_l 22 int l[1+SBMAX_l]; for (r0 = 0; r0 < 16; r0++) { ... for (r1 = 0; r1 < 8; r1++) { int a2 = gfc->scalefac_band.l[r0 + r1 + 2];
  • 15. Priority of * and ++ operations eMule is a client for ED2K file sharing network. STDMETHODIMP CCustomAutoComplete::Next(..., ULONG *pceltFetched) { ... if (pceltFetched != NULL) *pceltFetched++; ... } (*pceltFetched)++;
  • 16. Comparison mistake WinMerge — free open source software intended for the comparison and synchronization of files and directories. BUFFERTYPE m_nBufferType[2]; ... // Handle unnamed buffers if ((m_nBufferType[nBuffer] == BUFFER_UNNAMED) || (m_nBufferType[nBuffer] == BUFFER_UNNAMED)) nSaveErrorCode = SAVE_NO_FILENAME; By reviewing the code close by, this should contain: (m_nBufferType[0] == BUFFER_UNNAMED) || (m_nBufferType[1] == BUFFER_UNNAMED)
  • 17. Forgotten array index void lNormalizeVector_32f_P3IM(..., Ipp32s* mask, ...) { Ipp32s i; Ipp32f norm; for(i=0; i<len; i++) { if(mask<0) continue; ... } } if(mask[i]<0) continue; IPP Samples are samples demonstrating how to work with Intel Performance Primitives Library 7.0.
  • 18. Identical source code branches Notepad++ - free text editor for Windows supporting syntax highlight for a variety of programming languages. if (!_isVertical) if (!_isVertical) Flags |= DT_BOTTOM; Flags |= DT_VCENTER; else else Flags |= DT_BOTTOM; Flags |= DT_BOTTOM;
  • 19. Calling incorrect function with similar name What a beautiful comment. But it is sad that here we’re doing not what was intended. /** Deletes all previous field specifiers. * This should be used when dealing * with clients that send multiple NEP_PACKET_SPEC * messages, so only the last PacketSpec is taken * into account. */ int NEPContext::resetClientFieldSpecs(){ this->fspecs.empty(); return OP_SUCCESS; } /* End of resetClientFieldSpecs() */ Nmap Security Scanner – free utility intended for diverse customizable scanning of IP-networks with any number of objects and for identification of the statuses of the objects belonging to the network which is being scanned.
  • 20. Dangerous ?: operator Newton Game Dynamics – a well known physics engine which allows for reliable and fast simulation of environmental object’s physical behavior. den = dgFloat32 (1.0e-24f) * (den > dgFloat32(0.0f)) ? dgFloat32(1.0f) : dgFloat32(-1.0f); The priority of ?: is lower than that of multiplication operator *.
  • 21. And so on, and so on… if((t=(char *)realloc( next->name, strlen(name+1)))) FCE Ultra if((t=(char *)realloc( next->name, strlen(name)+1))) minX=max(0,minX+mcLeftStart-2); minY=max(0,minY+mcTopStart-2); maxX=min((int)width,maxX+mcRightEnd-1); maxY=min((int)height,maxX+mcBottomEnd-1); minX=max(0,minX+mcLeftStart-2); minY=max(0,minY+mcTopStart-2); maxX=min((int)width,maxX+mcRightEnd-1); maxY=min((int)height,maxY+mcBottomEnd-1);
  • 22. Low level memory management operations ID_INLINE mat3_t::mat3_t( float src[3][3] ) Return to Castle { Wolfenstein memcpy( mat, src, sizeof( src ) ); } ID_INLINE mat3_t::mat3_t( float (&src)[3][3] ) { memcpy( mat, src, sizeof( src ) ); } itemInfo_t *itemInfo; memset( itemInfo, 0, sizeof( &itemInfo ) ); memset( itemInfo, 0, sizeof( *itemInfo ) );
  • 23. Low level memory management operations CxImage – open image processing library. memset(tcmpt->stepsizes, 0, sizeof(tcmpt->numstepsizes * sizeof(uint_fast16_t))); memset(tcmpt->stepsizes, 0, tcmpt->numstepsizes * sizeof(uint_fast16_t));
  • 24. Low level memory management operations A beautiful example of 64-bit error: dgInt32 faceOffsetHitogram[256]; dgSubMesh* mainSegmenst[256]; memset (faceOffsetHitogram, 0, sizeof (faceOffsetHitogram)); memset (mainSegmenst, 0, sizeof (faceOffsetHitogram)); This code was duplicated but was not entirely corrected. As a result the size of pointer will not be equal to the size of dgInt32 type on Win64 and we will flush only a fraction of mainSegmenst array.
  • 25. Low level memory management operations #define CONT_MAP_MAX 50 int _iContMap[CONT_MAP_MAX]; ... memset(_iContMap, -1, CONT_MAP_MAX); memset(_iContMap, -1, CONT_MAP_MAX * sizeof(int));
  • 26. Low level memory management operations OGRE — open source Object-Oriented Graphics Rendering Engine written in C++. Real w, x, y, z; ... inline Quaternion(Real* valptr) { memcpy(&w, valptr, sizeof(Real)*4); } Yes, at present this is not a mistake. But it is a landmine!
  • 27. And a whole lot of other errors in well known projects • WinMerge • Chromium, Return to Castle Wolfenstein, etc • Miranda IM • Intel IPP Samples • Fennec Media Project • Ultimate Toolbox • Loki • eMule Plus, Pixie, VirtualDub, WinMerge, XUIFramework • Chromium • Qt • Apache HTTP Server • TortoiseSVN Here are the links to the articles containing descriptions of the errors: http://www.viva64.com/en/pvs-studio/
  • 28. Types of detectable errors • copy-paste errors; • Incorrect formatting strings (printf); • buffer overflow; • Incorrect utilization of STL, WinAPI; • ... • errors concerning the migration of 32-bit applications to 64-bit systems (Viva64); • errors concerning the incorrect usage of OpenMP;
  • 29. Integration • Visual Studio 2012: C, C++, C++11, C++/CX (WinRT). • Visual Studio 2010: C, C++, C++0x. • Visual Studio 2008: C, C++. • Visual Studio 2005: C, C++. • Embarcadero RAD Studio XE3: C, C++, C++11. • Embarcadero RAD Studio XE2: C, C++. • MinGW: C, C++.
  • 30. PVS-Studio Features • Incremental Analysis – verification of newly compiled files; • Verification of files which were recently modified several days ago; • Verification of files by their filenames from within the text file list; • continuous integration systems support; • version control systems integration; • ability to operate fro m command line interface; • «False Alarms» marking; • saving and loading of analysis results; • utilizing all available cores and processors; • interactive filters; • Russian and English online documentation; • Pdf documentation;
  • 31. Integration with Visual Studio 2005/2008/2010/2012
  • 33. Incremental Analysis – verification of newly compiled files • you just work with Visual Studio as usual; • compile by F7; • the verification of newly compiled files will start in background automatically; • At the end of verification the notification will appear, allowing you to inspect detected errors;
  • 34. VCS and CI support (revision control, continuous integration) • launching from command line: "C:Program Files (x86)PVS-Studiox64PVS-Studio.exe" --sln-file "C:UsersevgDocuments OmniSampleOmniSample (vs2008).sln" --plog-file "C:UsersevgDocumentsresult.plog" --vcinstalldir "C:Program Files (x86)Microsoft Visual Studio 9.0VC" --platform "x64" --configuration "Release” • sending the results by mail: cmd.exe /c type result-log.plog.only_new_messages.txt • commands for launching from CruiseControl.Net, Hudson, Microsoft TFS are readily available
  • 35. Interactive filters • filtering messages without restarting the analysis • Filtering by errors’ code, by filenames (including masks), by messages’ text, by warning levels; • displaying/hiding false alarms.
  • 36. Integrated help reference (description of the errors)
  • 37. PVS-Studio Advantages • Easy-to-download! You may download the PVS-Studio distribution package without registering and filling in any forms. • Easy-to-try! The PVS-Studio program is implemented as a plug-in for Visual Studio and Embarcadero RAD Studio. • Easy-to-buy! Unlike other code analyzers, we have simple pricing and licensing policy. • Easy-to-support! It is the analyzer's developers who directly communicate with users, which enables you to quickly get answers to even complicated questions related to programming.
  • 38. Pricing policy • a license for a team of no more than five developers is €5250; • prolongation for one year – 80% of base price; • the site license for teams with 20+ developers;
  • 39. Information about company OOO “Program Verification Systems” (Co Ltd) 300027, Russia, Tula, Metallurgov 70-1-88. www.viva64.com [email protected] Working time: 09:00 – 18:00 (GMT +3:00)