bug-fix: snprintf prints NULL in place of the last character (#10419)

* 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.

* add comment about extra null-term byte requirement
This commit is contained in:
kallewoof
2024-12-11 22:48:04 +09:00
committed by GitHub
parent 4b4d92b098
commit 484d2f31ae
2 changed files with 2 additions and 1 deletions

View File

@ -333,7 +333,7 @@ static std::string llama_get_chat_template(const struct llama_model * model) {
if (res < 2) {
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() - 1);
}