check if samplers size > seq id before access

This commit is contained in:
Gagan Nagaraj 2026-01-25 20:31:22 -07:00
parent 0c21677e43
commit 207eb94a51
2 changed files with 7 additions and 0 deletions

View File

@ -1195,6 +1195,9 @@ llama_context * common_init_result::context() {
}
common_sampler * common_init_result::sampler(llama_seq_id seq_id) {
if (pimpl->samplers.size() <= (size_t) seq_id) {
return nullptr;
}
return pimpl->samplers[seq_id].get();
}

View File

@ -144,6 +144,10 @@ int main(int argc, char ** argv) {
ctx = llama_init->context();
model = llama_init->model();
smpl = llama_init->sampler(0);
if (smpl == NULL) {
LOG_ERR("%s: error: unable to create sampler\n", __func__);
return 1;
}
if (ctx == NULL) {
LOG_ERR("%s: error: unable to create context\n", __func__);