An example of how new diagnostics appear in PVS-Studio

New C ++ diagnostics for PVS-Studio







Users sometimes ask how new diagnostics appear in the PVS-Studio static analyzer. We answer that we draw inspiration from a wide variety of sources: books, coding standards, our own mistakes, letters from our users, and so on. Today we came up with an interesting new diagnosis and decided to tell the story of how it happened.







It all started with checking the COVID-19 CovidSim Model project and an article about an uninitialized variable. The project turned out to be small and written using the modern C ++ language standard. This means that it can perfectly add to the base of test projects for regression testing of the PVS-Studio analyzer core.







, , , () . , - . , .







, , MISRA-. , , , , CovidSim.







MISRA MISRA C++ , . , goto (V2502), , . MISRA " MISRA ".







, CovidSim, MISRA . . , , . , MISRA, - :). , . MISRA , .







. , MISRA , V2507, .







if (radiusSquared > StateT[tn].maxRad2) StateT[tn].maxRad2 = radiusSquared;
{
  SusceptibleToLatent(a->pcell);
  if (a->listpos < Cells[a->pcell].S)
  {
    UpdateCell(Cells[a->pcell].susceptible, a->listpos, Cells[a->pcell].S);
    a->listpos = Cells[a->pcell].S;
    Cells[a->pcell].latent[0] = ai;
  }
}
StateT[tn].cumI_keyworker[a->keyworker]++;
      
      





V2507 .







, . ! ?







. , ! if.







:







if (radiusSquared > StateT[tn].maxRad2)
  StateT[tn].maxRad2 = radiusSquared;

{
  SusceptibleToLatent(a->pcell);
  ....
}
      
      





, . Top10 C++ , 2021 .







? , MISRA, ! , . , . , , .







, , MISRA, . – . , , . , .







. .







, if :







  • if then-;
  • statement if – compound statement, , if.


, .







. , - -, . , , . C# Java PVS-Studio.







, , PVS-Studio. CovidSim, MISRA .







++ :). Twitter. Facebook.







:







  1. , PVS-Studio .
  2. PVS-Studio Java: .
  3. .


, : Andrey Karpov. Example of How New Diagnostics Appear in PVS-Studio.








All Articles