From 2f1df890bdf74e308854214d514ad6fb91e5d116 Mon Sep 17 00:00:00 2001 From: s1lent Date: Sat, 18 Nov 2017 23:23:17 +0700 Subject: [PATCH] Bugfix: use size of buffer instead pointer --- metamod/src/utils.cpp | 5 ++--- metamod/src/utils.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/metamod/src/utils.cpp b/metamod/src/utils.cpp index cc7337e..ee3bed5 100644 --- a/metamod/src/utils.cpp +++ b/metamod/src/utils.cpp @@ -169,7 +169,7 @@ bool is_file_exists_in_gamedir(const char* path) // // Much like realpath, buffer pointed to by fullpath is assumed to be // able to store a string of PATH_MAX length. -char* full_gamedir_path(const char* path, char* fullpath) +char* full_gamedir_path(const char* path, char (&fullpath)[PATH_MAX]) { char buf[PATH_MAX]; @@ -184,8 +184,7 @@ char* full_gamedir_path(const char* path, char* fullpath) // Remove relative path components, if possible. if (!realpath(buf, fullpath)) { META_DEBUG(4, "Unable to get realpath for '%s': %s", buf, strerror(errno)); - Q_strncpy(fullpath, path, sizeof fullpath - 1); - fullpath[sizeof fullpath - 1] = '\0'; + Q_strlcpy(fullpath, path); } // Replace backslashes, etc. diff --git a/metamod/src/utils.h b/metamod/src/utils.h index 04c7316..085517c 100644 --- a/metamod/src/utils.h +++ b/metamod/src/utils.h @@ -32,7 +32,7 @@ bool is_abs_path(const char *path); bool is_valid_path(const char *path); bool is_platform_postfix(const char *pf); bool is_file_exists_in_gamedir(const char *path); -char *full_gamedir_path(const char *path, char *fullpath); +char *full_gamedir_path(const char *path, char (&fullpath)[PATH_MAX]); bool mem_compare(const char* addr, const char* pattern, size_t len); void NORETURN Sys_Error(const char *error, ...);