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

tests: lib: cmsis_dsp: Fix -Wsometimes-uninitialized warning #85182

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thughes
Copy link
Contributor

@thughes thughes commented Feb 4, 2025

Building with clang warns:

tests/lib/cmsis_dsp/distance/src/u32.c:82:3: error: variable 'val' is used uninitialized whenever switch default is taken [-Werror,-Wsometimes-uninitialized]
                default:
                ^~~~~~~
tests/lib/cmsis_dsp/distance/src/u32.c:87:19: note: uninitialized use occurs here
                output[index] = val;
                                ^~~
tests/lib/cmsis_dsp/distance/src/u32.c:47:16: note: initialize the variable 'val' to silence this warning
                float32_t val;
                             ^
                              = 0.0

Hitting the default switch will assert, so this won't cause any problems as written, but it doesn't hurt to initialize the variable.

@thughes thughes marked this pull request as ready for review February 5, 2025 00:11
@zephyrbot zephyrbot added size: XS A PR changing only a single line of code area: CMSIS-DSP labels Feb 5, 2025
@kartben
Copy link
Collaborator

kartben commented Feb 8, 2025

It feels like there has to be a better solution since this now means there is a very good chance the compiler will generate an additional instruction, will it not?

@thughes
Copy link
Contributor Author

thughes commented Feb 11, 2025

It feels like there has to be a better solution since this now means there is a very good chance the compiler will generate an additional instruction, will it not?

It's a test. Does it really matter?

@kartben
Copy link
Collaborator

kartben commented Feb 11, 2025

It feels like there has to be a better solution since this now means there is a very good chance the compiler will generate an additional instruction, will it not?

It's a test. Does it really matter?

Uh of course, I missed that, sorry!

Building with clang warns:

tests/lib/cmsis_dsp/distance/src/u32.c:82:3: error: variable 'val' is
used uninitialized whenever switch default is taken
[-Werror,-Wsometimes-uninitialized]
                default:
                ^~~~~~~
tests/lib/cmsis_dsp/distance/src/u32.c:87:19: note: uninitialized use
occurs here
                output[index] = val;
                                ^~~
tests/lib/cmsis_dsp/distance/src/u32.c:47:16: note: initialize the
variable 'val' to silence this warning
                float32_t val;
                             ^
                              = 0.0

Hitting the default switch will assert, so this won't cause any problems
as written, but it doesn't hurt to initialize the variable.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: CMSIS-DSP size: XS A PR changing only a single line of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants