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

Bluetooth: TBS: Fix -Wsometimes-uninitialized warning #85184

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

thughes
Copy link
Contributor

@thughes thughes commented Feb 4, 2025

Building bluetooth.shell.audio.only_gtbs with clang warns:

subsys/bluetooth/audio/tbs.c:1646:6: error: variable 'ret' is used uninitialized whenever 'if' condition is false
[-Werror,-Wsometimes-uninitialized]
        if (param->gtbs) {
            ^~~~~~~~~~~
subsys/bluetooth/audio/tbs.c:1667:9: note: uninitialized use occurs here
        return ret;
               ^~~
subsys/bluetooth/audio/tbs.c:1646:2: note: remove the 'if' if its condition is always true
        if (param->gtbs) {
        ^~~~~~~~~~~~~~~~~
subsys/bluetooth/audio/tbs.c:1626:9: note: initialize the variable 'ret' to silence this warning
        int ret;
               ^
                = 0

Copy link
Collaborator

@Thalley Thalley left a comment

Choose a reason for hiding this comment

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

This is fine as it fixes an issue.

It can only happen if CHECKIF is not enabled, otherwise it would always go into one of the branches, so perhaps we could also add an __ASSERT_NO_MSG(ret != -ENOEXEC) before the return ret?

Building bluetooth.shell.audio.only_gtbs with clang warns:

subsys/bluetooth/audio/tbs.c:1646:6: error: variable 'ret' is used
uninitialized whenever 'if' condition is false
[-Werror,-Wsometimes-uninitialized]
        if (param->gtbs) {
            ^~~~~~~~~~~
subsys/bluetooth/audio/tbs.c:1667:9: note: uninitialized use occurs here
        return ret;
               ^~~
subsys/bluetooth/audio/tbs.c:1646:2: note: remove the 'if' if its
condition is always true
        if (param->gtbs) {
        ^~~~~~~~~~~~~~~~~
subsys/bluetooth/audio/tbs.c:1626:9: note: initialize the variable 'ret'
to silence this warning
        int ret;
               ^
                = 0

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
@kartben kartben merged commit 8218bf6 into zephyrproject-rtos:main Feb 11, 2025
27 checks passed
@thughes thughes deleted the push-wzqszntlyvup branch February 11, 2025 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Audio area: Bluetooth size: XS A PR changing only a single line of code
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants