The assert macro caused a false positive

Make sure to read this post before raising a thread here:

Then tell us:

  • What language is this for?
    C++

  • Which rule?
    C S2259

  • Why do you believe it’s a false-positive/false-negative?
    Remove assert or change it to if, and no longer report an error

  • Are you using

    • SonarQube - developer edition 9.7
  • How can we reproduce the problem? Give us a self-contained snippet (best) or screenshot (good)
    #define COD_ASSERT(cond) assert (cond)

I could not reproduce the issue. Here is the full example I used:

void abort() __attribute__((noreturn));
#define NULL ((void*)0)
#define COD_ASSERT(cond) do { if (!(cond)) { abort(); } } while (false)

struct Node {
  int level;
};
Node *findNode(Node *mapper, int i);
void top(Node *node, Node *mapper, int i) {
  node = findNode(mapper, i);
  COD_ASSERT(node != NULL);
  node->level = mapper->level;
}

I only had a S960:Use an inline or static function instead issue for the COD_ASSERT definition.

Could you please upload the reproducer for your issue?
To generate the reproducer file:

  • Search in the analysis log for the full path of the source file for which you want to create a reproducer (the issue in this post). You will have to use exactly this name (same case, / or \…)
  • Add the reproducer option to the scanner configuration:
    sonar.cfamily.reproducer=“Full path to the .cpp”
  • Re-run the scanner to generate a file named sonar-cfamily.reproducer in the project folder.
  • Please share this file. If you think this file contains private information, let us know, and we’ll send you a private message that will allow you to send it privately.

Hi Balazs ,

 Thanks for your reply!
 We don't use abort() , can you use '#define COD_ASSERT(cond) assert (cond)' to reproduce the issue?

I still could not reproduce the issue.
I tried SonarQube 9.7.1, but SonarQube 9.7 should be no different on this regard.

First I thought that the assert-modeling improvement was not part of SonarQube 9.7, but that infact should be part of that release:

I would recommend to upgrade to the latest SonarQube version to confirm that this issue is still present on that version. It’s important that we accept reports only covering the latest LTS or the latest release of SonarQube. Check out the download page. AFAIK we just released SonarQube 9.9.

If the your issue is still present on any of those versions of SonarQube, I would recommend creating a reproducer file that I could investigate. I think that would be the most efficient way of resolving your situation. For the steps, see my previous reply.