Fix the following snprintf() string truncation warning: 013-cgroup_build_tasks_procs_path.cpp:65:22: warning: ‘%s’ directive output may be truncated writing up to 820799 bytes into a region of size 4081 [-Wformat-truncation=] 65 | "/sys/fs/cgroup/%s", cg_mount_table[i].name); | ^~ In file included from /usr/include/stdio.h:867, from /usr/include/c++/9/cstdio:42, from /usr/include/c++/9/ext/string_conversions.h:43, from /usr/include/c++/9/bits/basic_string.h:6493, from /usr/include/c++/9/string:55, from /usr/include/c++/9/bits/locale_classes.h:40, from /usr/include/c++/9/bits/ios_base.h:41, from /usr/include/c++/9/ios:42, from /usr/include/c++/9/ostream:38, from ../../googletest/googletest/include/gtest/gtest.h:55, from 013-cgroup_build_tasks_procs_path.cpp:22: /usr/include/x86_64-linux-gnu/bits/stdio2.h:67:35: note: ‘__builtin___snprintf_chk’ output between 16 an d 820815 bytes into a destination of size 4096 67 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 68 | __bos (__s), __fmt, __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Tom Hromatka <tom.hroma...@oracle.com> --- gunit/013-cgroup_build_tasks_procs_path.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gunit/013-cgroup_build_tasks_procs_path.cpp b/gunit/013-cgroup_build_tasks_procs_path.cpp index 7b778d058ca2..b86a68f56795 100644 --- a/gunit/013-cgroup_build_tasks_procs_path.cpp +++ b/gunit/013-cgroup_build_tasks_procs_path.cpp @@ -49,7 +49,7 @@ class BuildTasksProcPathTest : public ::testing::Test { char NAMESPACE1[] = "ns1"; char NAMESPACE4[] = "ns4"; const int ENTRY_CNT = 6; - int i; + int i, ret; memset(&cg_mount_table, 0, sizeof(cg_mount_table)); memset(cg_namespace_table, 0, @@ -61,8 +61,10 @@ class BuildTasksProcPathTest : public ::testing::Test { "controller%d", i); cg_mount_table[i].index = i; - snprintf(cg_mount_table[i].mount.path, FILENAME_MAX, + ret = snprintf(cg_mount_table[i].mount.path, FILENAME_MAX, "/sys/fs/cgroup/%s", cg_mount_table[i].name); + ASSERT_LT(ret, sizeof(cg_mount_table[i].mount.path)); + cg_mount_table[i].mount.next = NULL; if (i == 0) -- 2.25.1 _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel