Stories
Slash Boxes
Comments

SoylentNews is people

posted by martyb on Monday October 23 2017, @06:48AM   Printer-friendly
from the MY-code-is-perfect! dept.

I am really astonished by the capabilities of static code analysis. The tool surprised me the other day as it turned out to be smarter and more attentive than I am. I found I must be careful when working with static analysis tools. Code reported by the analyzer often looks fine and I'm tempted to discard the warning as a false positive and move on. I fell into this trap and failed to spot bugs...Even I, one of the PVS-Studio developers.

So, appreciate and use static code analyzers! They will help save your time and nerve cells.

[Ed note: I debated running this story as there was an element of self-promotion (aka Bin Spam), but the submitter has been with the site for a while and has posted informative comments. Besides, I know there have been far too many times when I've seen a compiler complain about some section of my code and I'm thinking there is nothing wrong with it — and then I, finally, see my mistake. Anyone have samples of code where you just knew the compiler or static analyzer was wrong, only to find out otherwise? --martyb]


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 0) by Anonymous Coward on Monday October 23 2017, @09:26PM (1 child)

    by Anonymous Coward on Monday October 23 2017, @09:26PM (#586584)

    You realize you are talking about a compiler from 1994 from a company that does not make compilers anymore right?

    and it worked up through about gcc 2.7
    The language specification changed. The compilers were keeping up. Most of the magazines of the time made a big deal about what the changes were. That was one of them.

    For your particular example it was not clear from the specification if the declaration was scoped inside of the loop or outside. Some compilers did it one way and some others (I had the joy of moving between a couple that interpreted it differently). The guys who wrote the original specification put what they intended into the ISO group meetings. It broke a few bits of my code too. It was an easy fix. Move the declaration outside of the loop initializer. Same effect and you were being clear you wanted the scope of that variable to be longer than the for loop which is what your code was doing and what you intended. The compiler does not interpret your intent. It interprets what you tell it.

  • (Score: 2, Troll) by aristarchus on Tuesday October 24 2017, @05:24AM

    by aristarchus (2645) on Tuesday October 24 2017, @05:24AM (#586727) Journal

    You realize you are talking about a compiler from 1994 from a company that does not make compilers anymore right?

    No, I did not realize this. Should I have? Could you have included indications of the irrelevance of your experience in your original post? Back in the early days of computing, we had to carry our own calcules, or pebbles, and an abacus, of course. And we had to both compile and test our algorithms by hand! Computer Scientists these days! What a bunch of wooshes!