@@ -63,6 +63,7 @@ static void llama_log_callback_default(llama_log_level level, const char * text,
63
63
#define LLAMA_LOG_WARN (...) llama_log_internal(LLAMA_LOG_LEVEL_WARN , __VA_ARGS__)
64
64
#define LLAMA_LOG_ERROR (...) llama_log_internal(LLAMA_LOG_LEVEL_ERROR, __VA_ARGS__)
65
65
66
+
66
67
#if !defined(GGML_USE_CUBLAS) && !defined(GGML_USE_METAL)
67
68
#include " ggml-alloc.h"
68
69
#define LLAMA_USE_ALLOCATOR
@@ -1988,7 +1989,7 @@ static bool llama_is_eos_token(const llama_vocab& vocab, llama_token token) {
1988
1989
return false ;
1989
1990
}
1990
1991
1991
- static bool llama_is_user_defined_token (const llama_vocab & vocab, llama_token token) {
1992
+ static bool llama_is_user_defined_token (const llama_vocab& vocab, llama_token token) {
1992
1993
UNUSED (vocab);
1993
1994
UNUSED (token);
1994
1995
// TODO: improve?
@@ -4400,24 +4401,24 @@ int llama_token_to_str_with_model(const struct llama_model * model, llama_token
4400
4401
if (0 <= token && token < llama_n_vocab_from_model (model)) {
4401
4402
if (llama_is_normal_token (model->vocab , token)) {
4402
4403
std::string result = model->vocab .id_to_token [token].tok ;
4403
- if (llama_vocab_type (model->vocab ) == " spm" ) {
4404
+ if (llama_vocab_type (model->vocab ) == " spm" ) {
4404
4405
result = llama_unescape_whitespace (result);
4405
4406
}
4406
4407
if (length < (int ) result.length ()) {
4407
4408
return -result.length ();
4408
4409
}
4409
- strcpy (str, result.c_str ());
4410
+ strncpy (str, result.c_str (), result. length ());
4410
4411
return result.length ();
4411
4412
} else if (llama_is_unknown_token (model->vocab , token)) {
4412
4413
if (length < 3 ) {
4413
4414
return -3 ;
4414
4415
}
4415
- strcpy (str, " \xe2\x96\x85 " );
4416
+ strncpy (str, " \xe2\x96\x85 " , 3 );
4416
4417
return 3 ;
4417
4418
} else if (llama_is_control_token (model->vocab , token)) {
4418
4419
;
4419
4420
} else if (llama_is_byte_token (model->vocab , token)) {
4420
- if ( 1 > length ) {
4421
+ if (length < 1 ) {
4421
4422
return -1 ;
4422
4423
}
4423
4424
str[0 ] = llama_byte_to_char (model->vocab , token);
@@ -4452,7 +4453,7 @@ int llama_token_to_str_bpe(const struct llama_context * ctx, llama_token token,
4452
4453
if (length < (int ) result.length ()) {
4453
4454
return -result.length ();
4454
4455
}
4455
- strcpy (str, result.c_str ());
4456
+ strncpy (str, result.c_str (), result. length ());
4456
4457
return result.length ();
4457
4458
}
4458
4459
return 0 ;
@@ -4463,9 +4464,8 @@ std::string llama_token_to_str_bpe(const struct llama_context * ctx, llama_token
4463
4464
const int length = llama_token_to_str_bpe (ctx, token, result.data (), result.size ());
4464
4465
if (length < 0 ) {
4465
4466
result.resize (-length);
4466
- const int check = llama_token_to_str_bpe (ctx, token, ( char *) result.data (), result.size ());
4467
+ const int check = llama_token_to_str_bpe (ctx, token, result.data (), result.size ());
4467
4468
GGML_ASSERT (check == -length);
4468
- GGML_UNUSED (check);
4469
4469
} else {
4470
4470
result.resize (length);
4471
4471
}
0 commit comments