From b55975fc0af368f3825efed4db8e2c2811222cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Tue, 12 Dec 2017 12:07:40 +0100 Subject: [PATCH] unittests: Fix printf float test BUFSIZE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/unittests/tests-printf_float/tests-printf_float.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unittests/tests-printf_float/tests-printf_float.c b/tests/unittests/tests-printf_float/tests-printf_float.c index dbcb0074aa..3c2ef1d44e 100644 --- a/tests/unittests/tests-printf_float/tests-printf_float.c +++ b/tests/unittests/tests-printf_float/tests-printf_float.c @@ -25,7 +25,7 @@ #include "tests-printf_float.h" -#define BUFSIZE (10) +#define BUFSIZE (12) static const double in0 = 2016.0349; static const double in1 = 123.4567; @@ -37,7 +37,7 @@ static void sfprintf_float(void) char *str = tmp; snprintf(str, BUFSIZE, "%f", in0); - TEST_ASSERT_EQUAL_STRING("2016.0349", str); + TEST_ASSERT_EQUAL_STRING("2016.034900", str); snprintf(str, BUFSIZE, "%.2f", in0); TEST_ASSERT_EQUAL_STRING("2016.03", str);