From 76135345c82a87fb9e76bbdaa110f3ca441c6033 Mon Sep 17 00:00:00 2001 From: Mohammad Azim Khan Date: Thu, 12 Apr 2018 13:23:01 +0100 Subject: [PATCH] Fix gcc-7 -Wformat-truncation warning Function test_snprintf() is called by run_test_snprintf() with constant test data. It gets inlined and is subjected to snprintf format truncation checks introduced by -Wformat-truncation in gcc-7. -Wformat-truncation is turned On by -Wall and other similar options. It results in error with -Werror. -Wformat-truncation makes tests performed by run_test_snprintf() redundant on gcc. But they are still relevant for other compilers. This commit prevents inlining of test_snprintf() to avoid gcc compile time checks. --- tests/suites/host_test.function | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/suites/host_test.function b/tests/suites/host_test.function index a4a5a8265..12431805f 100644 --- a/tests/suites/host_test.function +++ b/tests/suites/host_test.function @@ -339,6 +339,8 @@ static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret ) char buf[10] = "xxxxxxxxx"; const char ref[10] = "xxxxxxxxx"; + if( n >= sizeof( buf ) ) + return( -1 ); ret = mbedtls_snprintf( buf, n, "%s", "123" ); if( ret < 0 || (size_t) ret >= n ) ret = -1;