PVS-Studio

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
saso
Posts: 1224
Joined: Fri May 16, 2014 1:14 pm
Contact:

PVS-Studio

Postby saso » Sat Feb 16, 2019 8:30 pm

PVS-Studio Analyzer - Static Code Analysis for C, C++, C# and Java
https://www.viva64.com/en/pvs-studio/

Free PVS-Studio for open source projects
https://www.viva64.com/en/b/0600/

Adopting PVS-Studio in a large project. Part 1
https://www.youtube.com/watch?v=Jh-TP2jopTo

Adopting PVS-Studio in a large project. Part 2
https://www.youtube.com/watch?v=ZfYQMUISOIA

PVS-Studio for Linux. How to find bugs in the code?
https://www.youtube.com/watch?v=4SZxwRKo_os

How to write more reliable code - Egor Bredikhin - Meeting C++ 2018
https://www.youtube.com/watch?v=KpdSFZOQCl8
Last edited by saso on Sat Feb 23, 2019 9:09 am, edited 2 times in total.
User avatar
saso
Posts: 1224
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: PVS-Studio

Postby saso » Sat Feb 16, 2019 8:39 pm

I have created an analysis of the FreeCAD code (build 0.18.15892) with PVS-Studio. The report is available in an html format to all developers that are interested to have a look at it...

As always, take care of the possible false positives with this reports, some discussions about that can also be found in the below links for the LibreOffice report...

Here are a few links to a similar report that was done for the LibreOffice
https://www.viva64.com/en/b/0586/
https://bugs.documentfoundation.org/sho ... ?id=120703
https://cgit.freedesktop.org/libreoffic ... grep&q=pvs
wmayer
Site Admin
Posts: 14372
Joined: Thu Feb 19, 2009 10:32 am

Re: PVS-Studio

Postby wmayer » Sat Mar 09, 2019 12:13 pm

In the recent weeks I was working from time to time on many of the reported issues. So far I have fixed a good amount of them and pushed the changes to the repository, some are in a local branch and will be pushed after the v0.18 release and still around 100 are left to be fixed.

At the moment there are only two issues with priority "High". These are:
TaskProjGroup.cpp:405 and TaskProjGroup.cpp:407

Code: Select all


const char * TaskProjGroup::viewChkIndexToCStr(int index)
{
    //   Third Angle:  FTL  T  FTRight
    //                  L   F   Right   Rear
    //                 FBL  B  FBRight
    //
    //   First Angle:  FBRight  B  FBL
    //                  Right   F   L  Rear
    //                 FTRight  T  FTL
    assert (multiView != NULL);

    bool thirdAngle = multiView->usedProjectionType().isValue("Third Angle");
    switch(index) {
        case 0: return (thirdAngle ? "FrontTopLeft" : "FrontBottomRight");
        case 1: return (thirdAngle ? "Top" : "Bottom");
        case 2: return (thirdAngle ? "FrontTopRight" : "FrontBottomLeft");
        case 3: return (thirdAngle ? "Left" : "Right");
        case 4: return (thirdAngle ? "Front" : "Front");
        case 5: return (thirdAngle ? "Right" : "Left");
        case 6: return (thirdAngle ? "Rear" : "Rear");
        case 7: return (thirdAngle ? "FrontBottomLeft" : "FrontTopRight");
        case 8: return (thirdAngle ? "Bottom" : "Top");
        case 9: return (thirdAngle ? "FrontBottomRight" : "FrontTopLeft");
        default: return NULL;
    }
}
PVS is complaining about these two lines:

Code: Select all

case 4: return (thirdAngle ? "Front" : "Front");

Code: Select all

case 6: return (thirdAngle ? "Rear" : "Rear");
wandererfan wrote: ping
Is this on purpose that for the ? : operator in both cases the same value is returned or is it a copy-paste error?
wandererfan
Posts: 2705
Joined: Tue Nov 06, 2012 5:42 pm

Re: PVS-Studio

Postby wandererfan » Sat Mar 09, 2019 1:24 pm

wmayer wrote:
Sat Mar 09, 2019 12:13 pm
PVS is complaining about these two lines:

Code: Select all

case 4: return (thirdAngle ? "Front" : "Front");

Code: Select all

case 6: return (thirdAngle ? "Rear" : "Rear");
wandererfan wrote: ping
Is this on purpose that for the ? : operator in both cases the same value is returned or is it a copy-paste error?
The code is functionally correct.
Front and Rear views occupy the same position in both FirstAngle and ThirdAngle conventions. All the other views move between First and Third.
wmayer
Site Admin
Posts: 14372
Joined: Thu Feb 19, 2009 10:32 am

Re: PVS-Studio

Postby wmayer » Sat Mar 09, 2019 1:28 pm

OK, thanks for the clarification.
User avatar
saso
Posts: 1224
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: PVS-Studio

Postby saso » Mon Mar 11, 2019 10:10 pm

Happy to hear that the report was useful... Both thumbs up for fixing the issues this fast! :shock:
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

Re: PVS-Studio

Postby abdullah » Wed Mar 13, 2019 3:19 pm

saso wrote:
Mon Mar 11, 2019 10:10 pm
Happy to hear that the report was useful... Both thumbs up for fixing the issues this fast! :shock:
I have been looking to what Werner has pushed and I was very impressed with the detection capabilities of this tool.
wmayer
Site Admin
Posts: 14372
Joined: Thu Feb 19, 2009 10:32 am

Re: PVS-Studio

Postby wmayer » Wed Mar 13, 2019 3:53 pm

abdullah wrote:
Wed Mar 13, 2019 3:19 pm
saso wrote:
Mon Mar 11, 2019 10:10 pm
Happy to hear that the report was useful... Both thumbs up for fixing the issues this fast! :shock:
I have been looking to what Werner has pushed and I was very impressed with the detection capabilities of this tool.
It found many issues other code checking tools didn't find. However, there are a lot of false-positives and you have to look at all issues very carefully to avoid to make any regressions.

Other detected issues are formal correct but when following the advices it could happen that it will break the code when changing something in the class interface. So, it's best not to touch the relevant code.

So far I presumably have fixed around 30% (maybe more) of all issues.
wmayer
Site Admin
Posts: 14372
Joined: Thu Feb 19, 2009 10:32 am

Re: PVS-Studio

Postby wmayer » Wed Mar 13, 2019 4:26 pm

abdullah wrote:
Wed Mar 13, 2019 3:19 pm
saso wrote:
Mon Mar 11, 2019 10:10 pm
Happy to hear that the report was useful... Both thumbs up for fixing the issues this fast! :shock:
I have been looking to what Werner has pushed and I was very impressed with the detection capabilities of this tool.
At the moment there are left 15 issues I will have a look at. If you have some time then I will appreciate it if you can check the issues in CommandConstraints.cpp:4632, ..., with the description: Possible incorrect order of arguments passed to 'makeTangentToArcOfHyperbolaviaNewPoint' function: 'geom2' and 'geom1'.
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

Re: PVS-Studio

Postby abdullah » Wed Mar 13, 2019 4:30 pm

wmayer wrote:
Wed Mar 13, 2019 3:53 pm
abdullah wrote:
Wed Mar 13, 2019 3:19 pm
saso wrote:
Mon Mar 11, 2019 10:10 pm
Happy to hear that the report was useful... Both thumbs up for fixing the issues this fast! :shock:
I have been looking to what Werner has pushed and I was very impressed with the detection capabilities of this tool.
It found many issues other code checking tools didn't find. However, there are a lot of false-positives and you have to look at all issues very carefully to avoid to make any regressions.

Other detected issues are formal correct but when following the advices it could happen that it will break the code when changing something in the class interface. So, it's best not to touch the relevant code.

So far I presumably have fixed around 30% (maybe more) of all issues.
Thanks for letting me know this. Because you filter the false positives, I only see the good part of the tool.

It is good that I am trying to learn form the good part too ;)