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.
This commit is contained in:
Karl-Johan Alm 2024-11-20 15:23:59 +09:00
parent 3952a221af
commit 07a64b9fb6
No known key found for this signature in database
GPG key ID: CF78C98086AB1ECA

View file

@ -341,9 +341,9 @@ static std::string llama_get_chat_template(const struct llama_model * model) {
if (res < 0) {
return "";
} else {
std::vector<char> model_template(res, 0);
std::vector<char> 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);
}
}