[LTP] [PATCH 1/2] tst_cgroup: Fix -Wstringop-truncation warning

Petr Vorel pvorel@suse.cz
Tue Jul 26 17:56:45 CEST 2022


Add space for null terminator to fix warning:

tst_cgroup.c:505:17: warning: ‘__builtin_strncpy’ output may be truncated copying 255 bytes from a string of length 255 [-Wstringop-truncation]
  505 |                 strncpy(cgroup_test_dir, test_dir_name, NAME_MAX);
      |                 ^

Fixes: ebebdd735 ("API/cgroup: Implement tst_cg_load_config")

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 lib/tst_cgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 998b259a6..6f24e0450 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -502,7 +502,7 @@ static void cgroup_parse_config_line(const char *const config_entry)
 	}
 
 	if (!root->test_dir.dir_name && strcmp(test_dir_name, "NULL")) {
-		strncpy(cgroup_test_dir, test_dir_name, NAME_MAX);
+		strncpy(cgroup_test_dir, test_dir_name, NAME_MAX + 1);
 		cgroup_dir_mk(&root->ltp_dir, cgroup_test_dir, &root->test_dir);
 		root->test_dir.we_created_it = 1;
 	}
-- 
2.37.1



More information about the ltp mailing list