Assigned value is garbage or undefined - false positiv

code

	uint32_t freqconst = has_feature(brake_feautre_high_freq_pwm) ? 180 : 2000;
	htim2.Instance->CCR2 = partPerMillion * freqconst / 1000000L;

description

sonarqube says that freqconst is a garbage value, as fare as I can see no matter the result of has_feature freqconst should always be assigned. I have seen a couple of similar false-positives in other places.

system

Runing on sonarqube Developer Edition - Version 9.9 (build 65466)

Hi @grarup, welcome to the community!

The snippet you shared lacks the context, so we cannot investigate it to take any actions.
To help us, please share the reproducer of your specific case. Mind that this will capture the whole content of the selected file and its dependencies along with some logs.

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 (for instance, a file that contains a false-positive). 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.