Kev tshuaj xyuas ywj pheej ntawm PVS-Studio (Linux, C ++)

Kuv pom cov ntawv tshaj tawm uas PVS tau kawm los txheeb xyuas hauv Linux, thiab txiav txim siab sim nws ntawm kuv tus kheej cov haujlwm. Thiab qhov no yog qhov tshwm sim ntawm nws.


Txheem

  1. Yav tas los
  2. Daim ntawv
  3. Cov txiaj ntsim tau los
  4. Tom qab ntawd

Yav tas los

Teb kev txhawb nqa

Kuv thov tus yuam sij sim thiab lawv xa tuaj rau kuv tib hnub.

Cov ntaub ntawv meej meej

Peb tswj kom tso lub ntsuas ntsuas yam tsis muaj teeb meem. Kev pab rau console commands kuj muaj (txawm hais tias muaj qee qhov kev tsis txaus siab ntawm no, saib ntu Daim ntawv).

Muaj peev xwm ntawm kev txheeb xyuas ntau txoj xov

Lub ntsuas ntsuas muaj qhov "standard" xaiv -j, tso cai rau kev txheeb xyuas kom ua tiav nyob rau hauv tib lub sijhawm hauv ntau txoj haujlwm. Qhov no txuag tau ntau lub sijhawm.

Kev pom zoo

Muaj ntau ntau cov zis tawm tswv yim, los ntawm cov ntawv mus rau ib lub web muzzle me me. Lub vev xaib interface yog qhov yooj yim, meej, nrog cov lus qhia ib sab ntawm kab hauv cov cai thiab txuas mus rau cov lus piav qhia.

Kev sib xyaw yooj yim rau hauv kev sib dhos

Tag nrho cov ntaub ntawv yog nyob rau hauv lawv lub vev xaib, kuv tsuas tuaj yeem hais tias yog tias koj qhov project yog tsim los ntawm CMake, ces txhua yam yooj yim heev.

Cov lus piav qhia zoo

Yog tias koj tsim cov zis hauv hom fullhtml, tom qab ntawd txhua cov lus muaj qhov txuas mus rau cov lus piav qhia kuaj mob, nrog cov lus piav qhia, cov qauv lej thiab cov txuas ntxiv.

Daim ntawv

Ignorance ntawm C ++ lus los ntawm tus ntsuas

Hmoov tsis zoo, PVS qee zaum ua yuam kev syntax thiab tsim cov lus tsis raug zoo thaum cov cai yog tag nrho.

Piv txwv li, muaj ib txoj haujlwm uas rov qab los void:

template <typename T>
auto copy (const void * source, void * destination)
    ->
        std::enable_if_t
        <
            std::is_copy_constructible<T>::value
        >
{
    new (destination) T(*static_cast<const T *>(source));
}

Yog yog lo lus tseem ceeb auto txhais tau tias void, yog qhov nws yog rau pib. Tab sis PVS tau tsim cov lus hauv qab no:

dynamic_tuple_management.hpp:29:1: error: V591 Non-void function should return a value.
dynamic_tuple_management.hpp:29:1: error: V2542 Function with a non-void return type should return a value from all exit paths.

Qhov chaw qeeb heev

Yog lawm, nyob rau hauv lub web interface ntawm ib sab ntawm txhua cov lus muaj qhov txuas mus rau cov lus piav qhia txog kev txheeb xyuas nrog cov piv txwv. Tab sis thaum koj nyem rau ntawm qhov txuas, koj yuav tsum tau tos ntev heev, thiab qee zaum nws tshwm sim 504 Rooj vag Sijhawm tawm.

Lus

Tag nrho cov lus piav qhia yog nyob rau hauv Lavxias teb sab, uas zoo heev. Tab sis kev sib txuas los ntawm tsab ntawv ceeb toom ib txwm ua rau cov lus Askiv version. Nws yuav yog qhov zoo uas tuaj yeem hloov cov lus kom koj tuaj yeem pom kev kuaj mob tam sim hauv Lavxias. Kuv tsis pom qhov kev xaiv ntawd hauv lub interface.

Nws yog qhov tsis yooj yim rau kev ua haujlwm nrog qib kev kuaj mob ntawm lub console

Cia peb pib nrog qhov tseeb tias ob lo lus txib siv (qhov no pvs-studio-analyzer ΠΈ plog-converter) txawv hom ntawv rau kev txheeb xyuas.

Pab rau pvs-studio-analyzer nyeem:

-a [MODE], --analysis-mode [MODE]
    MODE defines the type of warnings:
    1 - 64-bit errors;
    2 - reserved;
    4 - General Analysis;
    8 - Micro-optimizations;
    16 - Customers Specific Requests;
    32 - MISRA.
    Modes can be combined by adding the values
    Default: 4

Kuv siv sijhawm ntev los sim seb yuav mus qhov twg ntxiv (β€œntxiv cov nqi”) cov yuam sij. Kuv sim sau lawv cais los ntawm commas:

pvs-studio-analyzer analyze ... -a 1,4,16

Kuv sim sau npe tus yuam sij ob peb zaug:

pvs-studio-analyzer analyze ... -a 1 -a 4 -a 16

Thiab tsuas yog tom qab ntawd kuv puas paub tias cov no yog qhov ncauj qhov ntswg me ntsis! Thiab koj xav tau ua sumthiab tsis ntxiv lub ntsiab lus. Piv txwv li, kom tau txais kev kuaj mob dav dav, kev kuaj mob rau micro-optimizations thiab MISRA, koj yuav tsum suav lawv (4 + 8 + 32 = 44):

pvs-studio-analyzer analyze ... -a 44

Kev siv bitmasks hauv cov neeg siv interfaces feem ntau yog daim ntawv tsis zoo. Tag nrho cov no tuaj yeem suav nrog sab hauv, thiab teeb tsa chij tuaj yeem teeb tsa rau tus neeg siv.

Tsis tas li ntawd, kuj muaj kev siv hluav taws xob plog-converter, uas generates human-readable static tsom xam cov ntaub ntawv. Nws muaj lwm yam teeb meem.

Pab rau qhov kev pab cuam plog-converter ceeb toom:

-a, --analyzer            Specifies analyzer(s) and level(s) to be
                          used for filtering, i.e.
                          'GA:1,2;64:1;OP:1,2,3;CS:1;MISRA:1,2'
                          Default: GA:1,2

Qee qhov "theem" ​​tshwm sim ntawm no uas tsis nyob ntawd ua ntej, thiab kuv tsis pom dab tsi txog lawv hauv cov ntaub ntawv ib yam.

Feem ntau, nws tsis meej. Tias yog vim li cas kuv teem txhua yam mus rau qhov siab tshaj plaws.

Ib pawg ntawm ruam swearing ntawm Catch

Ob ntawm peb txoj haujlwm kuv tau txheeb xyuas siv lub tsev qiv ntawv sim ntsuas Catch2. Thiab tus tsov ntxhuav feem ntawm cov lus (!!! 90 tawm ntawm 138 hauv ib qho thiab 297 tawm ntawm 344 hauv lwm qhov !!!) muaj daim ntawv hauv qab no:

Kev tshuaj xyuas ywj pheej ntawm PVS-Studio (Linux, C ++)

Tsis suav nrog multithreading

Muaj ntau qhov tsis zoo txog qhov xav tias tsis hloov pauv hloov pauv lossis tsis muaj qhov kawg, thaum ua haujlwm nrog cov kev hloov pauv no tshwm sim los ntawm cov xov sib txawv, thiab yog tias qhov no tsis yog, ces chav ntsuas yuav tsis ua haujlwm.

Kev tshuaj xyuas ywj pheej ntawm PVS-Studio (Linux, C ++)

Txawm li cas los xij, tus kws tshuaj ntsuam xyuas puas tuaj yeem coj qhov no mus rau hauv tus account? Tsis paub.

Cov txiaj ntsim tau los

PVS tsis pom muaj kab mob tiag tiag hauv kuv qhov chaw qhib Tawg nthe ΠΈ Ntxiv mus, raws li nyob rau hauv ib daim ntawv ua haujlwm, uas, vim li cas, kuv tsis tuaj yeem nthuav tawm. Muaj tseeb, nws tsim nyog nco ntsoov tias qee qhov kev tsis txaus ntseeg tau raug ntes thiab kho ua ntej siv Cppcheck ΠΈ scan-build.

Feem ntau, qhov kev xav los ntawm tag nrho cov kev ntsuas no yog kwv yees li qub: yog, lawv ntes ib yam dab tsi, qee zaum txawm tias ib qho tseem ceeb, tab sis tag nrho cov compiler txaus.

Nws yog qhov ua tau (thiab kuv tus kheej nyiam xav li ntawd) uas peb pab neeg siv software txhim kho kev coj ua uas tso cai rau peb los tsim qhov tsawg kawg nkaus ntawm shitty code. Nws yog qhov zoo dua tsis txhob tsim teeb meem ntau dua li kev kov yeej lawv tus kheej.

Yog li ntawd, kuv muaj kev ywj pheej ntawm kev muab qee cov lus qhia txog yuav ua li cas sau hauv C ++ hauv txoj hauv kev xws li tsis txhob tua leej twg ob txhais ceg tawm lossis ntaus ib tus neeg hauv pliaj nrog lub rake.

Ua qhov feem ntau ntawm kev kuaj xyuas compiler

Peb pab neeg siv (thiab qhia rau koj) cov kev xaiv muab tso ua ke hauv qab no:

-Werror

-Wall
-Wextra
-Wpedantic

-Wcast-align
-Wcast-qual
-Wconversion
-Wctor-dtor-privacy
-Wenum-compare
-Wfloat-equal
-Wnon-virtual-dtor
-Wold-style-cast
-Woverloaded-virtual
-Wredundant-decls
-Wsign-conversion
-Wsign-promo

Pab lawv hauv koj qhov project thiab kawm ntau yam txog koj cov cai.

Ua raws li tus qauv

Sim tsis txhob siv lub platform-dependent yam yog tias muaj cov qauv analogues, thiab yog tias koj tsis tuaj yeem ua yam tsis muaj lawv, qhwv lawv hauv cov block tshwj xeeb rau macros (lossis lwm yam) thiab tsuas yog tsis txhob cia koj cov cai muab tso ua ke nyob rau hauv cov xwm txheej tsis txaus siab.

Ua raws li cov txheej txheem ua haujlwm semantics

Ntxiv yuav tsum tau ntxiv, multiplication yuav tsum multiplication, muaj nuj nqi hu yuav tsum muaj nuj nqi hu, daim ntawv yuav tsum luam, nqa yuav tsum nqa, thawv yuav tsum iterable, iterator yuav tsum tau nce qib ++ thiab deferencing *. Thiab lwm yam thiab lwm yam.

Kuv xav tias lub tswv yim yog qhov tseeb. Muaj cov rooj sib tham uas tsis muaj kev khi, tab sis txhua tus neeg siv thiab cov neeg nyeem koj cov cai xav pom. Tsis txhob sim tawm tsam lwm tus, txwv tsis pub koj yuav tawm tsam koj tus kheej.

Sau cov cai sib xws

Ua ntej ntawm tag nrho cov, kuv txhais tau tias tus qauv tsev qiv ntawv. Nws yog qhov xav tau heev uas cov kev sib tshuam ntawm koj cov chav kawm thiab cov haujlwm tuaj yeem siv nrog cov qauv thiab lwm cov tsev qiv ntawv (piv txwv li, Boost).

Xav tias dawb mus saib ntawm STL thiab Boost interfaces. Tsis tshua muaj kev zam, koj yuav pom tus qauv tsim nyog nyob ntawd.

Ua qhov feem ntau ntawm cov cuab yeej qhib

Rau tib qhov kev tshuaj ntsuam zoo li qub, muaj tsawg kawg yog ob qhov qhib pub dawb uas tuaj yeem txuas nrog ib zaug rau ib qhov project nrog CMake tsim system.

Koj tuaj yeem nyeem ntxiv txog qhov no hauv kuv qhov kev tshaj tawm tsis ntev los no.

Tom qab ntawd

Thaum kawg, kuv xav hais tias kuv tsis tawm tswv yim tsis txhob siv PVS lossis lwm yam kev ntsuas zoo li qub. Tab sis kuv yaum kom koj xav txog yuav ua li cas nws tshwm sim uas tus neeg soj ntsuam zoo li qub pom qhov ua yuam kev tseem ceeb hauv koj cov cai.

Qhov no tsuas yog qhov tshwm sim. Peb yuav tsum nrhiav thiab tshem tawm qhov laj thawj.

Tau qhov twg los: www.hab.com

Ntxiv ib saib