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

Fix compile warnings in run_i2c_read #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jmaselbas
Copy link

when compiling ratp-barebox-cli I encountered the following warning/error message:

ratp-barebox-cli.c:682:16: error: ‘reglen’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
         printf ("Sending i2c-write request: bus:0x%02x addr:0x%02x reg:0x%0*x (+%zu bytes)\n",
                ^
ratp-barebox-cli.c:605:20: note: ‘reglen’ was declared here
     int            reglen;
                    ^
ratp-barebox-cli.c:560:16: error: ‘reglen’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
         printf ("Sending i2c-read request: bus:0x%02x addr:0x%02x reg:0x%0*x (+%lu bytes)\n",
                ^
ratp-barebox-cli.c:488:20: note: ‘reglen’ was declared here
     int            reglen;
                    ^

After a quick look at run_i2c_read, the reglen variable can indeed be used uninitialized, I also noticed a typo in the assert when parsing the reg value. See commit messages for more details.

Thanks

The reglen can be uninitialized when used by printf when logging the
i2c-read and i2c-write requests. Set a default value to 2 (two nibbles)
where the default reg value is set.
In run_i2c_read and run_i2c_write, the assert that verify that parsed
value do not exceed UINT16_MAX value should be verify against the reg
value (the one parsed) not against reglen which is only used for
printing, and only accepts values 2 or 4.
@jmaselbas
Copy link
Author

updated with same changes applied to i2c_write

@jmaselbas jmaselbas marked this pull request as draft January 24, 2023 11:12
@jmaselbas jmaselbas marked this pull request as ready for review January 24, 2023 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant