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

Li Wang liwang@redhat.com
Wed Jul 27 06:44:12 CEST 2022


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
>
>

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20220727/a8b15209/attachment.htm>


More information about the ltp mailing list