]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
util: fix compiler warning
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 3 Aug 2020 16:56:20 +0000 (18:56 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 4 Aug 2020 10:24:51 +0000 (12:24 +0200)
Replace the snprintf() call with memcpy() in UTI_PathToDir() to make it
clear a truncated string is expected.

util.c

diff --git a/util.c b/util.c
index 9743b99e993a32e98dcd71e6b1b46c451e2a196e..a572a02d4de4ec5041d092da88a13b0e67f8d781 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1032,6 +1032,7 @@ char *
 UTI_PathToDir(const char *path)
 {
   char *dir, *slash;
+  size_t dir_len;
 
   slash = strrchr(path, '/');
 
@@ -1041,8 +1042,11 @@ UTI_PathToDir(const char *path)
   if (slash == path)
     return Strdup("/");
 
-  dir = Malloc(slash - path + 1);
-  snprintf(dir, slash - path + 1, "%s", path);
+  dir_len = slash - path;
+
+  dir = Malloc(dir_len + 1);
+  memcpy(dir, path, dir_len);
+  dir[dir_len] = '\0';
 
   return dir;
 }