unittests: Fix printf float test BUFSIZE#8243
Merged
smlng merged 1 commit intoRIOT-OS:masterfrom Dec 19, 2017
Merged
Conversation
Fixes the following error from GCC 7.2.0 with a recent newlib
In file included from /usr/arm-none-eabi/include/stdio.h:800:0,
from /home/jgn/work/src/riot/tests/unittests/tests-printf_float/tests-printf_float.c:21:
/home/jgn/work/src/riot/tests/unittests/tests-printf_float/tests-printf_float.c: In function ‘sfprintf_float’:
/home/jgn/work/src/riot/tests/unittests/tests-printf_float/tests-printf_float.c:39:28: error: ‘%f’ directive output truncated writing 11 bytes into a region of size 10 [-Werror=format-truncation=]
snprintf(str, BUFSIZE, "%f", in0);
^
/home/jgn/work/src/riot/tests/unittests/tests-printf_float/tests-printf_float.c:39:5: note: ‘__builtin_snprintf’ output 12 bytes into a destination of size 10
snprintf(str, BUFSIZE, "%f", in0);
^
cc1: all warnings being treated as errors
13 tasks
smlng
approved these changes
Dec 15, 2017
Member
smlng
left a comment
There was a problem hiding this comment.
looks good to me, tested on macOS, too. No issue with this changes!
Member
Author
|
I tested with a build made with the current Docker riot/riotbuild image and it still works on Mulle (GCC 6.x). I think this is safe to merge. The C standard specifies that the %f printf format specifier when used without precision should give 6 digits after the decimal point. |
Member
well |
Member
Author
|
@smlng let's keep this until we find a C library which does not comply with the 6 digits by default rule. Edit: Do you agree? |
Member
|
ACK & GO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution description
Fixes the following error from GCC 7.2.0 with a recent newlib
The expected test output had to be updated as well, so it might be a good idea to re-run this on some other newlib versions. Tests pass on native and mulle.
Issues/PRs references
#8265