From 07a64b9fb611fc657ca27375e11255697a9a3317 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Wed, 20 Nov 2024 15:23:59 +0900 Subject: [PATCH] bug-fix: snprintf prints NULL in place of the last character We need to give snprintf enough space to print the last character and the null character, thus we allocate one extra byte and then ignore it when converting to std::string. --- examples/server/utils.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/server/utils.hpp b/examples/server/utils.hpp index c47ed3e47..335ec79f6 100644 --- a/examples/server/utils.hpp +++ b/examples/server/utils.hpp @@ -341,9 +341,9 @@ static std::string llama_get_chat_template(const struct llama_model * model) { if (res < 0) { return ""; } else { - std::vector model_template(res, 0); + std::vector model_template(res + 1, 0); llama_model_meta_val_str(model, template_key.c_str(), model_template.data(), model_template.size()); - return std::string(model_template.data(), model_template.size()); + return std::string(model_template.data(), model_template.size() - 1); } }