Clang SA false positive

Hello!

In my humble opinion that is a genuine false positive.

Unless we can see that printInt modifies zero, we should not write a warning. I would assume that external functions are “well behaved”.

Ø Why? Because even though it is static and printInt should not be able to modify it, printInt might be able to call into another function which can modify the value of zero.

Then the translation unit would have to for instance have a globally accessible function that modifies zero.

As I see it… we know that zero is not modified neither directly/indirectly by printInt if the provided code is the entire TU.

Best regards,

Daniel Marjamäki

  1. okt. 19. du. 3:14 ezt írta (“Daniel Marjamäki” <Daniel.Marjamaki@evidente.se>):

Hello!

In my humble opinion that is a genuine false positive.

Unless we can see that printInt modifies zero, we should not write a warning. I would assume that external functions are “well behaved”.

Ø Why? Because even though it is static and printInt should not be able to modify it, printInt might be able to call into another function which can modify the value of zero.

Then the translation unit would have to for instance have a globally accessible function that modifies zero.

Checking whether a globally available function can modify the static variable sounds like a good idea. I think it might worth a patch, to preserve the value in this case.

Hello!

Checking whether a globally available function can modify the static variable sounds like a good idea. I think it might worth a patch, to preserve the value in this case.

ok.

as I understand that would eliminate some FP but not all.

when using "well behaved" global functions there will be false positives.

imho whole program analysis is required to write these warnings.

Best regards,
Daniel Marjamäki

..................................................................................................................
Daniel Marjamäki Senior Engineer
Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden

Mobile: +46 (0)709 12 42 62
E-mail: Daniel.Marjamaki@evidente.se

www.evidente.se

Hi Gabor, Daniel,

I see! Thanks for your replies.