[PATCH] D139148: Fix nullptr dereference found by Coverity static analysis tool

Tom Honermann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 7 14:10:23 PST 2022


tahonermann added a comment.

Here is a simple test case that fails the assertion in the current location.

  struct B {
    B(int, int);
  };
  struct D : B {
    D() : B(0, 1) {}
  };

I spent a bit more time looking at the code and finally realized that `Initializer` is only assigned when `Args.size()` is exactly 1. So `Initializer` doesn't equate to whether or not an initializer is present; it equates to when exactly one initialization argument is present and in that case it aliases `Args[0]`. I don't like that, but deviating from it just to address a Coverity complaint doesn't seem justified.

I suggest we do this: add an assertion on `Initializer` at the beginning of each of the blocks that Coverity complained about. In my view of the source, that corresponds to lines 5939, 5958, and 6025.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139148/new/

https://reviews.llvm.org/D139148



More information about the cfe-commits mailing list