Skip to content

Conversation

@hujun260
Copy link
Contributor

@hujun260 hujun260 commented Jan 26, 2026

Summary

Fix compiler warning about uninitialized variable in the watchdog test. The flags variable in wdtest_rand() was not initialized and could trigger -Werror=maybe-uninitialized error on certain architectures (e.g., x86_64/intel64) where the compiler detects potential use before assignment.
should merge before apache/nuttx#18135

Changes

File: testing/ostest/wdog.c

  • Initialize flags variable to 0 at declaration
  • Fixes build error on qemu-intel64/nsh_pci_smp configuration

Root cause:
The flags variable is conditionally assigned only when cnt % 2 is true, but the compiler cannot determine at compile time that the corresponding leave_critical_section(flags) will only be called when the variable was actually assigned.

// Before: uninitialized
irqstate_t flags;

// After: initialized
irqstate_t flags = 0;

Initialize the flags variable to 0 to fix compiler warning about
potential use of uninitialized variable. The flags variable is
conditionally assigned in wdtest_rand() based on callback count.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

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

Thank you @hujun260 :-)

@xiaoxiang781216 xiaoxiang781216 merged commit 80c2b43 into apache:master Jan 26, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants