Libbson BCON_NEW false positive: Use the "nullptr" literal (cpp:S4962)

Whenever the BCON_NEW macro defined at mongo-c-driver/bcon.h at 5b91fb983fc5badf38e2debeb4ce6c231b73605b · mongodb/mongo-c-driver · GitHub is used, the line containing BCON_NEW triggers: Use the “nullptr” literal (cpp:S4962).

As this is a header we’re including, there is nothing we can do about this, so reporting it on our line of sourece code isnt useful. In addition the bson library is C, not C++, so it cant use nullptr either.

And these are defined within extern "C" { .. } which should turn off this C++ suggestion on a C macro.

c.f. mongo-c-driver/bson-macros.h at 5b91fb983fc5badf38e2debeb4ce6c231b73605b · mongodb/mongo-c-driver · GitHub

Hi @jayvdb,

You are right about the false-positive with extern C. I created a ticket to fix it.
For the part of raising an issue on an external macro, I wasn’t able to reproduce it. Can you provide an example or generate an automatic reproducer.

I tried this example and it didn’t raise an issue:

extern “C” {
int* nop(void* unused, …);
#define BCON_NEW(…) nop(NULL, VA_ARGS, (void *)NULL)
}

void f() {
int* i1 = BCON_NEW(1 ,2 ,3);

int* i2 = BCON_NEW(NULL, (void*)NULL);
}

To generate the automatic reproducer file:

  • Add the reproducer option to the scanner configuration:
    sonar.cfamily.reproducer= “Full path to the .cpp file that has or include the file that has the false-positive”
  • 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 you can send it privately.

Thanks,

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.