Skip to content

posix: syslog: Fix uninitialized variable error #69979

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

Merged
merged 1 commit into from
Mar 10, 2024

Conversation

jukkar
Copy link
Member

@jukkar jukkar commented Mar 8, 2024

Seen this in compiler

lib/posix/options/syslog.c: In function 'setlogmask': lib/posix/options/syslog.c:66:16: error: 'oldpri' may be used uninitialized
   66 |         return oldpri;
      |                ^~~~~~
lib/posix/options/syslog.c:59:13: note: 'oldpri' was declared here
   59 |         int oldpri;
      |             ^~~~~~
lib/posix/options/syslog.c: In function 'vsyslog':
lib/posix/options/syslog.c:83:33: error: 'mask' may be used uninitialized
   83 |         if ((BIT(level) & mask) == 0) {
      |             ~~~~~~~~~~~~~~~~~~~~^~~~
lib/posix/options/syslog.c:71:17: note: 'mask' was declared here
   71 |         uint8_t mask;
      |                 ^~~~

Seen this in compiler

lib/posix/options/syslog.c: In function 'setlogmask':
lib/posix/options/syslog.c:66:16: error: 'oldpri' may be used uninitialized
   66 |         return oldpri;
      |                ^~~~~~
lib/posix/options/syslog.c:59:13: note: 'oldpri' was declared here
   59 |         int oldpri;
      |             ^~~~~~
lib/posix/options/syslog.c: In function 'vsyslog':
lib/posix/options/syslog.c:83:33: error: 'mask' may be used uninitialized
   83 |         if ((BIT(level) & mask) == 0) {
      |             ~~~~~~~~~~~~~~~~~~~~^~~~
lib/posix/options/syslog.c:71:17: note: 'mask' was declared here
   71 |         uint8_t mask;
      |                 ^~~~

Signed-off-by: Jukka Rissanen <[email protected]>
@zephyrbot zephyrbot added the area: POSIX POSIX API Library label Mar 8, 2024
@zephyrbot zephyrbot requested review from cfriedt and ycsin March 8, 2024 15:11
Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is a bit of an annoyance - a few compilers seem unable to infer that K_SPINLOCK() is entered mostly unconditionally. So the same code that does not use that helper macro does not trip warnings, even with the variable uninitialized.

@cfriedt cfriedt merged commit 71fd9b2 into zephyrproject-rtos:main Mar 10, 2024
@jukkar jukkar deleted the fix/syslog-uinit-vars branch March 10, 2024 11:46
@illysky
Copy link
Contributor

illysky commented Oct 17, 2024

Hi

I think I am seeing the "may be used uninitialized" warning in:

zephyr/subsys/modem/modem_pipelink.c
zephyr/subsys/modem/modem_cmux.c

FYI. Some variables such as ret and connected are treated as uninitialized when inside K_SPINLOCK.
Building on STM32H7. Only happens when compiling with Debug optimisations. Similar to this issue: #78066

Only annoyance, as I treat warnings as errors.

@jukkar
Copy link
Member Author

jukkar commented Oct 18, 2024

I think I am seeing the "may be used uninitialized" warning in:

zephyr/subsys/modem/modem_pipelink.c zephyr/subsys/modem/modem_cmux.c

FYI. Some variables such as ret and connected are treated as uninitialized when inside K_SPINLOCK. Building on STM32H7. Only happens when compiling with Debug optimisations. Similar to this issue: #78066

Only annoyance, as I treat warnings as errors.

Would you be able to send a PR fixing these?

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

Successfully merging this pull request may close these issues.

6 participants