[cfe-dev] [clang-tidy] Check for paranoic code (pointer checking)

Richard via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 16 14:51:51 PDT 2017


[Please reply *only* to the list and do not include my email directly
in the To: or Cc: of your reply; otherwise I will not see your reply.
Thanks.]

In article <CAAt6xTtzDzbTmKwi_RjTuJt70mZ7RHL1GbR_2Bi5EUJTMSFBiA at mail.gmail.com>,
    Aaron Ballman via cfe-dev <cfe-dev at lists.llvm.org> writes:

> On Thu, Mar 16, 2017 at 12:54 AM, Breno GuimarĂ£es via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
>
> > 2 - Any feedback on this specific check?
> 
> Adding some intelligence to the check so that it suggests removing the
> validity check, or suggests replacing the pointer with a reference,
> when sensible to do so would make this a much better check IMO.

One very common case from programmers with a C background is to check
the result of new against NULL/nullptr/0.  Other static analyzers like
cppcheck have such a check already.  If clang/clang-tidy doesn't
already warn on code like this, that would be a good addition.

Another check in the same spirit is where code checks for non-nullptr
at some point and then checks against nullptr again.  This usually
happens in large functions where the earlier check against nullptr is
"out of sight, out of mind" when someone is adding the second check
against nullptr.

Again, this would be a welcome addition to clang/clang-tidy if we
don't already have something like that.
-- 
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
            The Terminals Wiki <http://terminals-wiki.org>
     The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
  Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>



More information about the cfe-dev mailing list