summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2022-06-24 14:33:32 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-07-07 18:43:57 +0000
commita32330b63cbf94c2314fc7bf62534ba4c7717e0d (patch)
tree4f84504efb057dfc1f22d0a4a88a680b2cf81610
parentff355e3dc31830f70b5ad603c5fce17e1ca012ce (diff)
downloadchrome-ec-a32330b63cbf94c2314fc7bf62534ba4c7717e0d.tar.gz
test/stdlib: Disable gcc stringop-truncation warning
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 <tomhughes@chromium.org> Change-Id: I943de03ae62d7ae5e431809305ae68100e6da418 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3724490 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r--test/build.mk3
-rw-r--r--test/stdlib.c8
2 files changed, 11 insertions, 0 deletions
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;