Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #30458

Re: Static analysis tool?

From Stefan Reuther <stefan.news@arcor.de>
Newsgroups comp.arch.embedded
Subject Re: Static analysis tool?
Date 2021-04-17 10:09 +0200
Message-ID <s5ec5j.5h0.1@stefan.msgid.phost.de> (permalink)
References <s5co8v$ck0$1@gioia.aioe.org>

Show all headers | View raw


Am 16.04.2021 um 21:24 schrieb Dave Nadler:
> Tried CPPcheck, and while it found some less-than-optimal stuff it only
> found one of the real bugs discussed.
> 
> Tried to get an evaluation copy of Coverity, but got a wildly annoying
> and clueless sales person who promises a member of the right team will
> contact me shortly (Real Soon Now).
> 
> Bugs I had to fix and amenable to static analysis included:
> - uninitialized variable (only one found by CPPcheck)
> - use of magic 0xff index value as subscript off end of array
> - C macro with unguarded arguments getting wrong answer
> - use of int8 to index 1kb buffer (so only 256 bytes got used)
> 
> Anybody able to recommend a tool they've used successfully?

First and foremost: if you've been sloppy for decades, throwing ANY tool
at the existing codebase will bury you in "findings" and therefore not
be useful. So, you WILL have to dumb down the tool to make it usable. If
you're giving out big money for the tool, it'll be hard to predict
whether you'll end up using 90% or 10% of it.

That aside, I consider the free tools good enough. The bang-for-the-buck
ratio is hard to beat:

Recent gcc and clang versions learned to detect a lot of things that
previously only specialized tools would find (e.g. switch/case
fallthrough). Just turn on the bulk for a first test (-O2 -Wall
-Wextra), and turn on even more stuff later. For example, we're using
-Wconversion which can be really annoying but has found/would have found
a few real bugs in our codebase. Of course this will bury you in
warnings if you haven't tried it before.

cppcheck has the advantage of knowing some APIs, i.e. it will find some
file descriptor leaks. On the downside, it has some annoying false
positives (e.g. in C++11, it will flag every other method of a local
class if one method is using std::move on a member).

Now I've also used Klocwork (which would be the same league as
Coverity), but consider its gain minimal. In our codebase, it produces
lots of false positives, some of which lead to sore forehead due to
excessive facepalming. One annoying example is its attempt to implement
the MISRA pseudo-type system, where '1 << 10' is an error because '1'
has type uint8_t for MISRA. Problem is, it considers 'UINT32_C(1)' to
have type uint8_t as well. Another annoying example is that whenever I
call a class method 'open', it expects a call to 'close' somewhere or
flags a resource leak. And sometimes it gets lost inside STL and tells
me that standard class has a leak; at least you won't have that problem
when checking only C :) On the plus side, it has a database to silence
one finding for the future.


  Stefan

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Static analysis tool? Dave Nadler <drn@nadler.com> - 2021-04-16 15:24 -0400
  Re: Static analysis tool? Helmut Giese <hgiese@ratiosoft.com> - 2021-04-16 21:44 +0200
  Re: Static analysis tool? Don Y <blockedofcourse@foo.invalid> - 2021-04-16 12:56 -0700
    Re: Static analysis tool? Dave Nadler <drn@nadler.com> - 2021-04-16 16:26 -0400
      Re: Static analysis tool? Don Y <blockedofcourse@foo.invalid> - 2021-04-16 13:47 -0700
        Re: Static analysis tool? Don Y <blockedofcourse@foo.invalid> - 2021-04-16 13:54 -0700
    Re: Static analysis tool? Gerhard Hoffmann <dk4xp@arcor.de> - 2021-04-16 22:54 +0200
      Re: Static analysis tool? Don Y <blockedofcourse@foo.invalid> - 2021-04-16 14:20 -0700
  Re: Static analysis tool? Paul Rubin <no.email@nospam.invalid> - 2021-04-17 01:04 -0700
  Re: Static analysis tool? Stefan Reuther <stefan.news@arcor.de> - 2021-04-17 10:09 +0200
  Re: Static analysis tool? Michael Kellett <mk@mkesc.co.uk> - 2021-04-17 10:45 +0100
  Re: Static analysis tool? David Brown <david.brown@hesbynett.no> - 2021-04-17 12:51 +0200
  Re: Static analysis tool? Dave Nadler <drn@nadler.com> - 2021-04-17 10:34 -0400
    Re: Static analysis tool? Dave Nadler <drn@nadler.com> - 2021-05-02 11:41 -0400
      Re: Static analysis tool? Don Y <blockedofcourse@foo.invalid> - 2021-05-02 08:49 -0700

csiph-web