@@ -4555,24 +4555,24 @@ int llama_token_to_str_with_model(const struct llama_model * model, llama_token
4555
4555
if (0 <= token && token < llama_n_vocab_from_model (model)) {
4556
4556
if (llama_is_normal_token (model->vocab , token)) {
4557
4557
std::string result = model->vocab .id_to_token [token].tok ;
4558
- if (llama_vocab_type (model->vocab ) == " spm" ) {
4558
+ if (llama_vocab_type (model->vocab ) == " spm" ) {
4559
4559
result = llama_unescape_whitespace (result);
4560
4560
}
4561
4561
if (length < (int ) result.length ()) {
4562
4562
return -result.length ();
4563
4563
}
4564
- strcpy (str, result.c_str ());
4564
+ strncpy (str, result.c_str (), result. length ());
4565
4565
return result.length ();
4566
4566
} else if (llama_is_unknown_token (model->vocab , token)) {
4567
4567
if (length < 3 ) {
4568
4568
return -3 ;
4569
4569
}
4570
- strcpy (str, " \xe2\x96\x85 " );
4570
+ strncpy (str, " \xe2\x96\x85 " , 3 );
4571
4571
return 3 ;
4572
4572
} else if (llama_is_control_token (model->vocab , token)) {
4573
4573
;
4574
4574
} else if (llama_is_byte_token (model->vocab , token)) {
4575
- if ( 1 > length ) {
4575
+ if (length < 1 ) {
4576
4576
return -1 ;
4577
4577
}
4578
4578
str[0 ] = llama_byte_to_char (model->vocab , token);
@@ -4607,7 +4607,7 @@ int llama_token_to_str_bpe(const struct llama_context * ctx, llama_token token,
4607
4607
if (length < (int ) result.length ()) {
4608
4608
return -result.length ();
4609
4609
}
4610
- strcpy (str, result.c_str ());
4610
+ strncpy (str, result.c_str (), result. length ());
4611
4611
return result.length ();
4612
4612
}
4613
4613
return 0 ;
@@ -4618,9 +4618,8 @@ std::string llama_token_to_str_bpe(const struct llama_context * ctx, llama_token
4618
4618
const int length = llama_token_to_str_bpe (ctx, token, result.data (), result.size ());
4619
4619
if (length < 0 ) {
4620
4620
result.resize (-length);
4621
- const int check = llama_token_to_str_bpe (ctx, token, ( char *) result.data (), result.size ());
4621
+ const int check = llama_token_to_str_bpe (ctx, token, result.data (), result.size ());
4622
4622
GGML_ASSERT (check == -length);
4623
- GGML_UNUSED (check);
4624
4623
} else {
4625
4624
result.resize (length);
4626
4625
}
0 commit comments