From 93c18c5903e82c7b35b8faa39dfb9648c4d77b29 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Tue, 21 Jul 2020 18:36:11 +0200 Subject: [PATCH] Fix gcc V10 warnings in sysstat 12.0.1 code used for test The tests/ directory contains an old version of sysstat code (v 12.0.1) used for non regression tests. Compiling this version produces warnings with recent gcc v9/v10. Fix them, even if we alter a bit the original 12.0.1 code. Signed-off-by: Sebastien GODARD --- tests/12.0.1/common.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/12.0.1/common.c b/tests/12.0.1/common.c index 5406fc6..ebcf249 100644 --- a/tests/12.0.1/common.c +++ b/tests/12.0.1/common.c @@ -776,11 +776,12 @@ char *strtolower(char *str) */ char *get_persistent_type_dir(char *type) { - static char dir[32]; + static char dir[PATH_MAX]; + int n; - snprintf(dir, 32, "%s-%s", DEV_DISK_BY, type); + n = snprintf(dir, sizeof(dir), "%s-%s", DEV_DISK_BY, type); - if (access(dir, R_OK)) { + if ((n >= sizeof(dir)) || access(dir, R_OK)) { return (NULL); } @@ -801,11 +802,12 @@ char *get_persistent_type_dir(char *type) char *get_persistent_name_path(char *name) { static char path[PATH_MAX]; + int n; - snprintf(path, PATH_MAX, "%s/%s", - get_persistent_type_dir(persistent_name_type), name); + n = snprintf(path, PATH_MAX, "%s/%s", + get_persistent_type_dir(persistent_name_type), name); - if (access(path, F_OK)) { + if ((n >= sizeof(path)) || access(path, F_OK)) { return (NULL); } -- 2.40.0