From a32330b63cbf94c2314fc7bf62534ba4c7717e0d Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 24 Jun 2022 14:33:32 -0700 Subject: test/stdlib: Disable gcc stringop-truncation warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc warns: error: ‘__builtin_strncpy’ output truncated copying 10 bytes from a string of length 12 [-Werror=stringop-truncation] In this case the test is intentionally copying a subset of the string. Also, since it's not obvious, add a note that when building this test for the host we're actually testing the toolchain's C standard library, not the EC "builtin" version. BRANCH=none BUG=b:234181908, b:237823627 TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes Change-Id: I943de03ae62d7ae5e431809305ae68100e6da418 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3724490 Reviewed-by: Jack Rosenthal --- test/build.mk | 3 +++ test/stdlib.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/test/build.mk b/test/build.mk index afe46453e0..e7cc18d2e8 100644 --- a/test/build.mk +++ b/test/build.mk @@ -91,6 +91,9 @@ test-list-host += sha256_unrolled test-list-host += shmalloc test-list-host += static_if test-list-host += static_if_error +# TODO(b/237823627): When building for the host, we're linking against the +# toolchain's C standard library, so these tests are actually testing the +# toolchain's C standard library. test-list-host += stdlib test-list-host += system test-list-host += thermal diff --git a/test/stdlib.c b/test/stdlib.c index 4d9a4d6f87..cd018af09b 100644 --- a/test/stdlib.c +++ b/test/stdlib.c @@ -120,7 +120,15 @@ static int test_strncpy(void) TEST_ASSERT_ARRAY_EQ("test", dest, 5); strncpy(dest, "12345", 6); TEST_ASSERT_ARRAY_EQ("12345", dest, 6); + /* + * gcc complains: + * error: ‘__builtin_strncpy’ output truncated copying 10 bytes from a + * string of length 12 [-Werror=stringop-truncation] + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" strncpy(dest, "testtesttest", 10); +#pragma GCC diagnostic pop TEST_ASSERT_ARRAY_EQ("testtestte", dest, 10); return EC_SUCCESS; -- cgit v1.2.1