Message ID | 20220726155646.26468-2-pvorel@suse.cz |
---|---|
State | Accepted |
Headers | show |
Series | Minor tst_cgroup improvements | expand |
On Tue, Jul 26, 2022 at 11:56 PM Petr Vorel <pvorel@suse.cz> wrote: > 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> > Reviewed-by: Li Wang <liwang@redhat.com> > --- > 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 > >
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; }
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(-)