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

Ubuntu artful and bionic warn about printing an uint16_t formatted as "%2X", taking 2 to 4 bytes #862

Open
jimklimov opened this issue Nov 9, 2020 · 0 comments
Labels
CI Entries related to continuous integration infrastructure (historically also recipes like Makefiles) portability We want NUT to build and run everywhere possible

Comments

@jimklimov
Copy link
Member

jimklimov commented Nov 9, 2020

https://github.com/networkupstools/nut/blob/master/drivers/al175.c#L400

	snprintf(data+2, 6+1, "%2X%2X%2X", pr1, pr2, pr3);

http://buildbot.networkupstools.org/public/nut/builders/Ubuntu-artful-x64/builds/240/steps/compile/logs/warnings%20%284%29 and http://buildbot.networkupstools.org/public/nut/builders/Ubuntu-bionic-x64/builds/185/steps/compile/logs/warnings%20%281%29 :

../../../drivers/al175.c:400:28: warning: '%2X' directive output may be truncated writing between 2 and 4 bytes into a region of size between 3 and 5 [-Wformat-truncation=]

I am in favor of finding a way to silence this one warning, unless someone comes up with reasoning why it makes sense. For now, PR #858 would add a comment here that the warning exists in a rare test case, but seems bogus.

Probably bumping the target buffer size might avoid this like in other such cases, but I really wonder if there is a way for explicit %2X of an explicitly 16-bit variable to print more than two data bytes?.. Do some distros/compilers account for wide chars for example? Then we'd have a lot more such warnings on that platform, I suppose...

@jimklimov jimklimov changed the title Ubuntu artful warns about printing an uint16_t formatted as "%2X", taking 2 to 4 bytes Ubuntu artful and bionic warn about printing an uint16_t formatted as "%2X", taking 2 to 4 bytes Nov 9, 2020
@jimklimov jimklimov added CI Entries related to continuous integration infrastructure (historically also recipes like Makefiles) portability We want NUT to build and run everywhere possible labels Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Entries related to continuous integration infrastructure (historically also recipes like Makefiles) portability We want NUT to build and run everywhere possible
Projects
None yet
Development

No branches or pull requests

1 participant