]> granicus.if.org Git - sysstat/commitdiff
Fix gcc V10 warnings in sysstat 12.0.1 code used for test
authorSebastien GODARD <sysstat@users.noreply.github.com>
Tue, 21 Jul 2020 16:36:11 +0000 (18:36 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Tue, 21 Jul 2020 16:36:11 +0000 (18:36 +0200)
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 <sysstat@users.noreply.github.com>
tests/12.0.1/common.c

index 5406fc6824161012860eb7f7c0bbdf7d38ee3ade..ebcf249ca931b3ff4a2fb051babc0bb2bcd2aca2 100644 (file)
@@ -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);
        }