util: fix compiler warning
Replace the snprintf() call with memcpy() in UTI_PathToDir() to make it clear a truncated string is expected.
This commit is contained in:
parent
6a5665ca58
commit
4993c35e11
1 changed files with 6 additions and 2 deletions
8
util.c
8
util.c
|
@ -1032,6 +1032,7 @@ char *
|
||||||
UTI_PathToDir(const char *path)
|
UTI_PathToDir(const char *path)
|
||||||
{
|
{
|
||||||
char *dir, *slash;
|
char *dir, *slash;
|
||||||
|
size_t dir_len;
|
||||||
|
|
||||||
slash = strrchr(path, '/');
|
slash = strrchr(path, '/');
|
||||||
|
|
||||||
|
@ -1041,8 +1042,11 @@ UTI_PathToDir(const char *path)
|
||||||
if (slash == path)
|
if (slash == path)
|
||||||
return Strdup("/");
|
return Strdup("/");
|
||||||
|
|
||||||
dir = Malloc(slash - path + 1);
|
dir_len = slash - path;
|
||||||
snprintf(dir, slash - path + 1, "%s", path);
|
|
||||||
|
dir = Malloc(dir_len + 1);
|
||||||
|
memcpy(dir, path, dir_len);
|
||||||
|
dir[dir_len] = '\0';
|
||||||
|
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue