[CRIU] [PATCH] cr-service: fix gcc-8 error
Adrian Reber
adrian at lisas.de
Thu Aug 2 13:30:34 MSK 2018
From: Adrian Reber <areber at redhat.com>
The latest patches to cr-service.c broke compilation with gcc-8:
criu/cr-service.c: In function ‘setup_opts_from_req’:
criu/cr-service.c:323:3: error: ‘strncpy’ specified bound 4096 equals destination size [-Werror=stringop-truncation]
strncpy(images_dir_path, opts.imgs_dir, PATH_MAX);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
criu/cr-service.c:343:3: error: ‘strncpy’ specified bound 4096 equals destination size [-Werror=stringop-truncation]
strncpy(work_dir_path, opts.work_dir, PATH_MAX);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
This fixes the errors by specifying the strncpy() size as 'PATH_MAX - 1'.
Signed-off-by: Adrian Reber <areber at redhat.com>
---
criu/cr-service.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/criu/cr-service.c b/criu/cr-service.c
index dc2ff05f7..643aba9cf 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -320,7 +320,7 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
* * apply_config(rpc_conf)
*/
if (opts.imgs_dir && imgs_changed_by_rpc_conf)
- strncpy(images_dir_path, opts.imgs_dir, PATH_MAX);
+ strncpy(images_dir_path, opts.imgs_dir, PATH_MAX - 1);
else
sprintf(images_dir_path, "/proc/%d/fd/%d", ids.pid, req->images_dir_fd);
@@ -340,7 +340,7 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
/* chdir to work dir */
if (opts.work_dir && work_changed_by_rpc_conf)
- strncpy(work_dir_path, opts.work_dir, PATH_MAX);
+ strncpy(work_dir_path, opts.work_dir, PATH_MAX - 1);
else if (req->has_work_dir_fd)
sprintf(work_dir_path, "/proc/%d/fd/%d", ids.pid, req->work_dir_fd);
else
--
2.18.0
More information about the CRIU
mailing list