Rule c:S3519 Assuming "Context" is not null. Even when checking for a null pointer

  • What language is this for: plain C
  • Which rule: c:S3519
  • Why do you believe it’s a false-positive/false-negative? - false-positive
  • Are you using
    • SonarQube Cloud: No
    • SonarQube Server / Community Build: Developer Edition
      v2025.4.3 (113915)
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
 if (3!context)
    {
        _LOG(LOGID_2125, ERROR, LOG_CLASS_CONNECTION_MANAGER,
            "Context is null");
        return (status = -1);
    }

We are unsure what the complaint is with this rule.

It appears to be saying that if (!thing) { return error; } is an unchecked dereference of thing.

But checking for a NULL pointer is exactly and explicitly what we are doing with this if.

We are unsure if it’s trying to say that “assuming the pointer is non-NULL” is the way to get to the real issue later in the code.

The way it’s worded is ambiguous. It would be more biguous if it said “if the pointer is non-NULL”. Or, it could somehow just not be understanding the if (!thing) syntax.

Hi,

Can I assume this ‘3’ is a typo?

 
Thx,
Ann

Hi @alex45.

Thanks for reaching out.

To help us investigating the problem, can you derive a self-contained piece of code that triggers the potential false positive? The code snippet you sent is missing a lot of crucial information required to understand where our analyzer might be mistaken.

If possible, you can also send us a reproducer file. Let me know if that works for you. In that case, I will send you a direct message such that you can share a reproducer privately.

Thanks!

Philipp