@@ -63,6 +63,7 @@ static void llama_log_callback_default(llama_log_level level, const char * text,
6363#define  LLAMA_LOG_WARN (...)  llama_log_internal(LLAMA_LOG_LEVEL_WARN , __VA_ARGS__)
6464#define  LLAMA_LOG_ERROR (...) llama_log_internal(LLAMA_LOG_LEVEL_ERROR, __VA_ARGS__)
6565
66+ 
6667#if  !defined(GGML_USE_CUBLAS) && !defined(GGML_USE_METAL)
6768#include  " ggml-alloc.h" 
6869#define  LLAMA_USE_ALLOCATOR 
@@ -1988,7 +1989,7 @@ static bool llama_is_eos_token(const llama_vocab& vocab, llama_token token) {
19881989        return  false ;
19891990}
19901991
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) {
19921993    UNUSED (vocab);
19931994    UNUSED (token);
19941995    //  TODO: improve?
@@ -4400,24 +4401,24 @@ int llama_token_to_str_with_model(const struct llama_model * model, llama_token
44004401    if  (0  <= token && token < llama_n_vocab_from_model (model)) {
44014402        if  (llama_is_normal_token (model->vocab , token)) {
44024403            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" 
44044405                result = llama_unescape_whitespace (result);
44054406            }
44064407            if  (length < (int ) result.length ()) {
44074408                return  -result.length ();
44084409            }
4409-             strcpy (str, result.c_str ());
4410+             strncpy (str, result.c_str (), result. length ());
44104411            return  result.length ();
44114412        } else  if  (llama_is_unknown_token (model->vocab , token)) {
44124413            if  (length < 3 ) {
44134414                return  -3 ;
44144415            }
4415-             strcpy (str, " \xe2\x96\x85 " 
4416+             strncpy (str, " \xe2\x96\x85 " ,  3 );
44164417            return  3 ;
44174418        } else  if  (llama_is_control_token (model->vocab , token)) {
44184419            ;
44194420        } else  if  (llama_is_byte_token (model->vocab , token)) {
4420-             if ( 1  > length ) {
4421+             if  (length <  1 ) {
44214422                return  -1 ;
44224423            }
44234424            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,
44524453        if  (length < (int ) result.length ()) {
44534454            return  -result.length ();
44544455        }
4455-         strcpy (str, result.c_str ());
4456+         strncpy (str, result.c_str (), result. length ());
44564457        return  result.length ();
44574458    }
44584459    return  0 ;
@@ -4463,9 +4464,8 @@ std::string llama_token_to_str_bpe(const struct llama_context * ctx, llama_token
44634464    const  int  length = llama_token_to_str_bpe (ctx, token, result.data (), result.size ());
44644465    if  (length < 0 ) {
44654466        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 ());
44674468        GGML_ASSERT (check == -length);
4468-         GGML_UNUSED (check);
44694469    } else  {
44704470        result.resize (length);
44714471    }
0 commit comments