From 4993c35e11cc641568811fcdddabc75348c64c1a Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 3 Aug 2020 18:56:20 +0200 Subject: [PATCH] util: fix compiler warning Replace the snprintf() call with memcpy() in UTI_PathToDir() to make it clear a truncated string is expected. --- util.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util.c b/util.c index 9743b99..a572a02 100644 --- 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; }