Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninitialised variable in print_exponential_number #123

Closed
mattbucknall opened this issue Mar 1, 2022 · 14 comments
Closed

Uninitialised variable in print_exponential_number #123

mattbucknall opened this issue Mar 1, 2022 · 14 comments

Comments

@mattbucknall
Copy link

Hi - I get the following warning when compiling printf.c (master [8b831c1]):

printf.c:899:47: warning: 'abs_exp10_covered_by_powers_table' may be used uninitialized in this function [-Wmaybe-uninitialized]

I've not done any in-depth analysis of how print_exponential_number works, so I'm not sure if this really matters. Still, it would be nice if abs_exp10_covered_by_powers_table could be initialised with a default value to get rid of this warning.

@eyalroz
Copy link
Owner

eyalroz commented Mar 1, 2022

This is a compiler "bug". Look at the logic:

  // ... snip ...
  if (abs_number == 0.0) {
    floored_exp10 = 0;
  }
  else  {
    // ... snip ...
    abs_exp10_covered_by_powers_table = false;
    // ... snip ...
  }
  // ... snip ...
  normalization.multiply = (floored_exp10 < 0 && abs_exp10_covered_by_powers_table);
  // ... snip ...

You see? It can't be used uninitialized. See it GodBolt also.

What compiler are you using?

@eyalroz eyalroz closed this as completed Mar 1, 2022
@203Null
Copy link

203Null commented Apr 8, 2022

I have the same issue with using this library with ESP-IDF

image

@eyalroz
Copy link
Owner

eyalroz commented Apr 8, 2022

I have the same issue with using this library with ESP-IDF

I don't know what ESP-IDF means. Please file a bug against either the IDE or the compiler it uses to generate warnings.

@203Null
Copy link

203Null commented Apr 8, 2022

I don't know what ESP-IDF means. Please file a bug against either the IDE or the compiler it uses to generate warnings.

It will not compile with -Wmaybe-uninitialized unless I default abs_exp10_covered_by_powers_table to false.

@203Null
Copy link

203Null commented Apr 8, 2022

image

@eyalroz
Copy link
Owner

eyalroz commented Apr 8, 2022

First of all, you're treating warnings as errors. That is your prerogative, but the library's build mechanism does not do that on its own.

Secondly, and again - a warning here is a bug in your compiler. There is no sense in complaining about it here. The code is correct. Please file a bug against the compiler.

@203Null
Copy link

203Null commented Apr 8, 2022

First of all, you're treating warnings as errors. That is your prerogative, but the library's build mechanism does not do that on its own.

Secondly, and again - a warning here is a bug in your compiler. There is no sense in complaining about it here. The code is correct. Please file a bug against the compiler.

The only place that abs_exp10_covered_by_powers_table is defined is at

abs_exp10_covered_by_powers_table = PRINTF_ABS(floored_exp10) < PRINTF_MAX_PRECOMPUTED_POWER_OF_10;

which is under an if-else statement. I don't see how this is a compiler error.

@203Null
Copy link

203Null commented Apr 8, 2022

I see, the code won't check for abs_exp10_covered_by_powers_table if floored_exp10 == 0

@eyalroz
Copy link
Owner

eyalroz commented Apr 8, 2022

@203Null : Exactly.

@203Null
Copy link

203Null commented Apr 8, 2022

The compiler I used is Xtensa ESP32 gcc 8.4.0 (2021r2)
On GodBolt with the same compiler, it works fine https://godbolt.org/z/8W65Ga38n

I will make an issue in their Github repo

eyalroz added a commit that referenced this issue Jun 3, 2022
eyalroz added a commit that referenced this issue Jul 23, 2022
eyalroz added a commit that referenced this issue Oct 17, 2022
@203Null
Copy link

203Null commented Nov 3, 2022

I saw you did some commits regarding this issue.

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

Those codes are actually fine with my compiler (not sure about others)

These lines in print_exponential_number are actually the ones causing issues for me. Porting your changes over solves it.

normalization.multiply = (floored_exp10 < 0 && abs_exp10_covered_by_powers_table);

@eyalroz
Copy link
Owner

eyalroz commented Nov 4, 2022

@203Null : Please open a separate about your issue; explain exactly on which system and with which compiler in what version you get an error, and copy the relevant compiler output.

@203Null
Copy link

203Null commented Nov 6, 2022

@203Null : Please open a separate about your issue; explain exactly on which system and with which compiler in what version you get an error, and copy the relevant compiler output.

It's the exact same issue. I posted my log earlier #123

Just want to point out the #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" was added to the wrong place (I assume you added them to fix this issue judging by the commit name.)

@eyalroz
Copy link
Owner

eyalroz commented Nov 6, 2022

Ok, I'll add the pragma there as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants