From 78812c6d638c3dba75a521d39bfeca5c30af6310 Mon Sep 17 00:00:00 2001 From: Pierrick HYMBERT Date: Sat, 16 Mar 2024 20:02:34 +0100 Subject: [PATCH] llama_load_model_from_url: PR feedback, use snprintf instead of strncp and strncat --- common/common.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/common/common.cpp b/common/common.cpp index 5775840dd..90902542a 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -1667,16 +1667,14 @@ struct llama_model * llama_load_model_from_url(const char * model_url, const cha struct stat buffer; auto file_exists = (stat(path_model, &buffer) == 0); - // If the file exists, check for ${model_path}.etag or ${model_path}.lastModified files + // If the file exists, check for ${path_model}.etag or ${path_model}.lastModified files char etag[LLAMA_CURL_MAX_HEADER_LENGTH] = {0}; char etag_path[LLAMA_CURL_MAX_PATH_LENGTH] = {0}; - strncpy(etag_path, path_model, LLAMA_CURL_MAX_PATH_LENGTH - 6); // 6 is the length of ".etag\0" - strncat(etag_path, ".etag", 6); + snprintf(etag_path, sizeof(etag_path), "%s.etag", path_model); char last_modified[LLAMA_CURL_MAX_HEADER_LENGTH] = {0}; char last_modified_path[LLAMA_CURL_MAX_PATH_LENGTH] = {0}; - strncpy(last_modified_path, path_model, LLAMA_CURL_MAX_PATH_LENGTH - 15); // 15 is the length of ".lastModified\0" - strncat(last_modified_path, ".lastModified", 15); + snprintf(last_modified_path, sizeof(last_modified_path), "%s.lastModified", path_model); if (file_exists) { auto * f_etag = fopen(etag_path, "r");