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: 4, Interesting) by shortscreen on Monday October 23 2017, @10:16AM (3 children)

    by shortscreen (2252) on Monday October 23 2017, @10:16AM (#586251) Journal

    One time I thought a 68K linker was outputting a section with reversed byte order, so as a workaround I flipped the byte order of the data... Until later when I noticed that my own code was reversing the byte order at run time :p

    It gets more interesting when you write stuff and run it in an emulator, since emulators regularly have bugs. One time I wrote something that caused the emulator itself to crash. I contacted the authors, they fixed something, and uploaded a new version of the emulator. I tried the fixed version and it didn't crash but my program still didn't work. I contacted them again, and they said that my code was sending nonsense parameters to the (emulated) hardware, which is what had triggered their bug. Oops.

    One time I complained that a different emulator was not handling an interrupt status bit correctly. Someone replied that there was no status bit, the register was marked write-only in the documentation. I looked at the documentation, and they were right. But my code ran correctly on the real hardware, the documentation was wrong!

    One time I found a legit bug in FreeBASIC, but I was using an old version and by that time it had already been fixed in subsequent versions.

    Starting Score:    1  point
    Moderation   +2  
       Interesting=2, Total=2
    Extra 'Interesting' Modifier   0  
    Karma-Bonus Modifier   +1  

    Total Score:   4  
  • (Score: 3, Informative) by bzipitidoo on Monday October 23 2017, @10:35AM (2 children)

    by bzipitidoo (4388) on Monday October 23 2017, @10:35AM (#586258) Journal

    One bug I know of in Applesoft BASIC (on the Apple II+ computer) happens if you use a variable named just "A". Write "IF B>A THEN" and the interpreter will parse that as "IF B> AT HEN" and bomb on that line. Have to put parentheses around the condition, or switch the order of the variables in the comparison: "IF A<B THEN"

    • (Score: 0) by Anonymous Coward on Monday October 23 2017, @03:30PM (1 child)

      by Anonymous Coward on Monday October 23 2017, @03:30PM (#586370)

      Is that really a bug? I mean, subtraction and division aren't commutative either.

      • (Score: 3, Informative) by bzipitidoo on Monday October 23 2017, @11:11PM

        by bzipitidoo (4388) on Monday October 23 2017, @11:11PM (#586637) Journal

        Didn't have anything to do with commutativity. It was "A THEN" that the interpreter couldn't handle. It would see that as the keyword "AT" followed by a variable named "HEN". You might say it laid an egg at that point :D.