chore: replacement of std string functions with builtin (#4194)

Signed-off-by: FASTSHIFT <vifextech@foxmail.com>
This commit is contained in:
_VIFEXTech
2023-05-01 17:56:46 +08:00
committed by GitHub
parent 7be3bfd962
commit ac84ae23de
25 changed files with 128 additions and 93 deletions

View File

@@ -103,10 +103,10 @@ lv_disp_t * lv_linux_fbdev_create(void)
void lv_linux_fbdev_set_file(lv_disp_t * disp, const char * file) void lv_linux_fbdev_set_file(lv_disp_t * disp, const char * file)
{ {
char * devname = lv_malloc(strlen(file) + 1); char * devname = lv_malloc(lv_strlen(file) + 1);
LV_ASSERT_MALLOC(devname); LV_ASSERT_MALLOC(devname);
if(devname == NULL) return; if(devname == NULL) return;
strcpy(devname, file); lv_strcpy(devname, file);
lv_linux_fb_t * dsc = lv_disp_get_driver_data(disp); lv_linux_fb_t * dsc = lv_disp_get_driver_data(disp);
dsc->devname = devname; dsc->devname = devname;

View File

@@ -68,7 +68,7 @@ static void sdl_keyboard_read(lv_indev_t * indev, lv_indev_data_t * data)
{ {
lv_sdl_keyboard_t * dev = lv_indev_get_driver_data(indev); lv_sdl_keyboard_t * dev = lv_indev_get_driver_data(indev);
const size_t len = strlen(dev->buf); const size_t len = lv_strlen(dev->buf);
/*Send a release manually*/ /*Send a release manually*/
if(dev->dummy_read) { if(dev->dummy_read) {
@@ -121,7 +121,7 @@ void _lv_sdl_keyboard_handler(SDL_Event * event)
const uint32_t ctrl_key = keycode_to_ctrl_key(event->key.keysym.sym); const uint32_t ctrl_key = keycode_to_ctrl_key(event->key.keysym.sym);
if(ctrl_key == '\0') if(ctrl_key == '\0')
return; return;
const size_t len = strlen(dsc->buf); const size_t len = lv_strlen(dsc->buf);
if(len < KEYBOARD_BUFFER_SIZE - 1) { if(len < KEYBOARD_BUFFER_SIZE - 1) {
dsc->buf[len] = ctrl_key; dsc->buf[len] = ctrl_key;
dsc->buf[len + 1] = '\0'; dsc->buf[len + 1] = '\0';
@@ -129,7 +129,7 @@ void _lv_sdl_keyboard_handler(SDL_Event * event)
break; break;
} }
case SDL_TEXTINPUT: { /*Text input*/ case SDL_TEXTINPUT: { /*Text input*/
const size_t len = strlen(dsc->buf) + strlen(event->text.text); const size_t len = lv_strlen(dsc->buf) + lv_strlen(event->text.text);
if(len < KEYBOARD_BUFFER_SIZE - 1) if(len < KEYBOARD_BUFFER_SIZE - 1)
strcat(dsc->buf, event->text.text); strcat(dsc->buf, event->text.text);
} }

View File

@@ -111,14 +111,14 @@ lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_co
dsc->frame_id = frame_id; dsc->frame_id = frame_id;
if(dsc->src_type == LV_IMG_SRC_FILE) { if(dsc->src_type == LV_IMG_SRC_FILE) {
size_t fnlen = strlen(src); size_t fnlen = lv_strlen(src);
dsc->src = lv_malloc(fnlen + 1); dsc->src = lv_malloc(fnlen + 1);
LV_ASSERT_MALLOC(dsc->src); LV_ASSERT_MALLOC(dsc->src);
if(dsc->src == NULL) { if(dsc->src == NULL) {
LV_LOG_WARN("out of memory"); LV_LOG_WARN("out of memory");
return LV_RES_INV; return LV_RES_INV;
} }
strcpy((char *)dsc->src, src); lv_strcpy((char *)dsc->src, src);
} }
else { else {
dsc->src = src; dsc->src = src;

View File

@@ -666,7 +666,7 @@ static int ffmpeg_update_next_frame(struct ffmpeg_context_s * ffmpeg_ctx)
struct ffmpeg_context_s * ffmpeg_open_file(const char * path) struct ffmpeg_context_s * ffmpeg_open_file(const char * path)
{ {
if(path == NULL || strlen(path) == 0) { if(path == NULL || lv_strlen(path) == 0) {
LV_LOG_ERROR("file path is empty"); LV_LOG_ERROR("file path is empty");
return NULL; return NULL;
} }

View File

@@ -174,7 +174,7 @@ lv_font_t * lv_freetype_font_create(const char * pathname, uint16_t size, uint16
lv_free(dsc); lv_free(dsc);
return NULL; return NULL;
} }
strcpy(dsc->pathname, pathname); lv_strcpy(dsc->pathname, pathname);
dsc->size = size; dsc->size = size;
dsc->style = style; dsc->style = style;

View File

@@ -257,9 +257,9 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
if(fno.fattrib & AM_DIR) { if(fno.fattrib & AM_DIR) {
fn[0] = '/'; fn[0] = '/';
strcpy(&fn[1], fno.fname); lv_strcpy(&fn[1], fno.fname);
} }
else strcpy(fn, fno.fname); else lv_strcpy(fn, fno.fname);
} while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0); } while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0);

View File

@@ -239,7 +239,7 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
char buf[256]; char buf[256];
lv_snprintf(buf, sizeof(buf), LV_FS_POSIX_PATH "%s\\*", path); lv_snprintf(buf, sizeof(buf), LV_FS_POSIX_PATH "%s\\*", path);
strcpy(next_fn, ""); lv_strcpy(next_fn, "");
d = FindFirstFile(buf, &fdata); d = FindFirstFile(buf, &fdata);
do { do {
if(strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) { if(strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) {
@@ -278,16 +278,16 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
entry = readdir(dir_p); entry = readdir(dir_p);
if(entry) { if(entry) {
if(entry->d_type == DT_DIR) sprintf(fn, "/%s", entry->d_name); if(entry->d_type == DT_DIR) sprintf(fn, "/%s", entry->d_name);
else strcpy(fn, entry->d_name); else lv_strcpy(fn, entry->d_name);
} }
else { else {
strcpy(fn, ""); lv_strcpy(fn, "");
} }
} while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0); } while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0);
#else #else
strcpy(fn, next_fn); lv_strcpy(fn, next_fn);
strcpy(next_fn, ""); lv_strcpy(next_fn, "");
WIN32_FIND_DATA fdata; WIN32_FIND_DATA fdata;
if(FindNextFile(dir_p, &fdata) == false) return LV_FS_RES_OK; if(FindNextFile(dir_p, &fdata) == false) return LV_FS_RES_OK;

View File

@@ -240,7 +240,7 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
char buf[MAX_PATH_LEN]; char buf[MAX_PATH_LEN];
lv_snprintf(buf, sizeof(buf), LV_FS_STDIO_PATH "%s\\*", path); lv_snprintf(buf, sizeof(buf), LV_FS_STDIO_PATH "%s\\*", path);
strcpy(handle->next_fn, ""); lv_strcpy(handle->next_fn, "");
handle->dir_p = FindFirstFileA(buf, &fdata); handle->dir_p = FindFirstFileA(buf, &fdata);
do { do {
if(strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) { if(strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) {
@@ -283,16 +283,16 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
entry = readdir(handle->dir_p); entry = readdir(handle->dir_p);
if(entry) { if(entry) {
if(entry->d_type == DT_DIR) sprintf(fn, "/%s", entry->d_name); if(entry->d_type == DT_DIR) sprintf(fn, "/%s", entry->d_name);
else strcpy(fn, entry->d_name); else lv_strcpy(fn, entry->d_name);
} }
else { else {
strcpy(fn, ""); lv_strcpy(fn, "");
} }
} while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0); } while(strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0);
#else #else
strcpy(fn, handle->next_fn); lv_strcpy(fn, handle->next_fn);
strcpy(handle->next_fn, ""); lv_strcpy(handle->next_fn, "");
WIN32_FIND_DATAA fdata; WIN32_FIND_DATAA fdata;
if(FindNextFileA(handle->dir_p, &fdata) == false) return LV_FS_RES_OK; if(FindNextFileA(handle->dir_p, &fdata) == false) return LV_FS_RES_OK;

View File

@@ -373,7 +373,7 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
lv_snprintf(buf, sizeof(buf), "%s\\*", path); lv_snprintf(buf, sizeof(buf), "%s\\*", path);
#endif #endif
strcpy(handle->next_fn, ""); lv_strcpy(handle->next_fn, "");
handle->dir_p = FindFirstFileA(buf, &fdata); handle->dir_p = FindFirstFileA(buf, &fdata);
do { do {
if(is_dots_name(fdata.cFileName)) { if(is_dots_name(fdata.cFileName)) {
@@ -413,9 +413,9 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
{ {
LV_UNUSED(drv); LV_UNUSED(drv);
dir_handle_t * handle = (dir_handle_t *)dir_p; dir_handle_t * handle = (dir_handle_t *)dir_p;
strcpy(fn, handle->next_fn); lv_strcpy(fn, handle->next_fn);
lv_fs_res_t current_error = handle->next_error; lv_fs_res_t current_error = handle->next_error;
strcpy(handle->next_fn, ""); lv_strcpy(handle->next_fn, "");
WIN32_FIND_DATAA fdata; WIN32_FIND_DATAA fdata;

View File

@@ -445,7 +445,7 @@ char * lv_fs_get_letters(char * buf)
const char * lv_fs_get_ext(const char * fn) const char * lv_fs_get_ext(const char * fn)
{ {
size_t i; size_t i;
for(i = strlen(fn); i > 0; i--) { for(i = lv_strlen(fn); i > 0; i--) {
if(fn[i] == '.') { if(fn[i] == '.') {
return &fn[i + 1]; return &fn[i + 1];
} }
@@ -459,7 +459,7 @@ const char * lv_fs_get_ext(const char * fn)
char * lv_fs_up(char * path) char * lv_fs_up(char * path)
{ {
size_t len = strlen(path); size_t len = lv_strlen(path);
if(len == 0) return path; if(len == 0) return path;
len--; /*Go before the trailing '\0'*/ len--; /*Go before the trailing '\0'*/
@@ -485,7 +485,7 @@ char * lv_fs_up(char * path)
const char * lv_fs_get_last(const char * path) const char * lv_fs_get_last(const char * path)
{ {
size_t len = strlen(path); size_t len = lv_strlen(path);
if(len == 0) return path; if(len == 0) return path;
len--; /*Go before the trailing '\0'*/ len--; /*Go before the trailing '\0'*/

View File

@@ -12,6 +12,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include "lv_printf.h" #include "lv_printf.h"
#include "lv_mem.h"
#include "../hal/lv_hal_tick.h" #include "../hal/lv_hal_tick.h"
#if LV_LOG_PRINTF #if LV_LOG_PRINTF
@@ -85,7 +86,7 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line, const char *
/*Use only the file name not the path*/ /*Use only the file name not the path*/
size_t p; size_t p;
for(p = strlen(file); p > 0; p--) { for(p = lv_strlen(file); p > 0; p--) {
if(file[p] == '/' || file[p] == '\\') { if(file[p] == '/' || file[p] == '\\') {
p++; /*Skip the slash*/ p++; /*Skip the slash*/
break; break;

View File

@@ -69,9 +69,23 @@ void lv_free(void * data);
*/ */
void * lv_realloc(void * data_p, size_t new_size); void * lv_realloc(void * data_p, size_t new_size);
/**
* @brief Copies a block of memory from a source address to a destination address.
* @param dst Pointer to the destination array where the content is to be copied.
* @param src Pointer to the source of data to be copied.
* @param len Number of bytes to copy.
* @return Pointer to the destination array.
* @note The function does not check for any overlapping of the source and destination memory blocks.
*/
void * lv_memcpy(void * dst, const void * src, size_t len); void * lv_memcpy(void * dst, const void * src, size_t len);
/**
* @brief Fills a block of memory with a specified value.
* @param dst Pointer to the destination array to fill with the specified value.
* @param v Value to be set. The value is passed as an int, but the function fills
* the block of memory using the unsigned char conversion of this value.
* @param len Number of bytes to be set to the value.
*/
void lv_memset(void * dst, uint8_t v, size_t len); void lv_memset(void * dst, uint8_t v, size_t len);
/** /**
@@ -84,15 +98,34 @@ static inline void lv_memzero(void * dst, size_t len)
lv_memset(dst, 0x00, len); lv_memset(dst, 0x00, len);
} }
/**
* @brief Computes the length of the string str up to, but not including the terminating null character.
* @param str Pointer to the null-terminated byte string to be examined.
* @return The length of the string in bytes.
*/
size_t lv_strlen(const char * str); size_t lv_strlen(const char * str);
/**
* @brief Copies up to dest_size characters from the string pointed to by src to the character array pointed to by dst.
* @param dst Pointer to the destination array where the content is to be copied.
* @param src Pointer to the source of data to be copied.
* @param dest_size Maximum number of characters to be copied to dst, including the null character.
* @return A pointer to the destination array, which is dst.
*/
char * lv_strncpy(char * dst, const char * src, size_t dest_size); char * lv_strncpy(char * dst, const char * src, size_t dest_size);
/**
* @brief Copies the string pointed to by src, including the terminating null character,
* to the character array pointed to by dst.
* @param dst Pointer to the destination array where the content is to be copied.
* @param src Pointer to the source of data to be copied.
* @return A pointer to the destination array, which is dst.
*/
char * lv_strcpy(char * dst, const char * src); char * lv_strcpy(char * dst, const char * src);
/** /**
* * @brief Tests the memory allocation system by allocating and freeing a block of memory.
* @return * @return LV_RES_OK if the memory allocation system is working properly, or LV_RES_INV if there is an error.
*/ */
lv_res_t lv_mem_test(void); lv_res_t lv_mem_test(void);

View File

@@ -420,8 +420,8 @@ void _lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt)
{ {
if(txt_buf == NULL || ins_txt == NULL) return; if(txt_buf == NULL || ins_txt == NULL) return;
size_t old_len = strlen(txt_buf); size_t old_len = lv_strlen(txt_buf);
size_t ins_len = strlen(ins_txt); size_t ins_len = lv_strlen(ins_txt);
if(ins_len == 0) return; if(ins_len == 0) return;
size_t new_len = ins_len + old_len; size_t new_len = ins_len + old_len;
@@ -441,7 +441,7 @@ void _lv_txt_cut(char * txt, uint32_t pos, uint32_t len)
{ {
if(txt == NULL) return; if(txt == NULL) return;
size_t old_len = strlen(txt); size_t old_len = lv_strlen(txt);
pos = _lv_txt_encoded_get_byte_id(txt, pos); /*Convert to byte index instead of letter index*/ pos = _lv_txt_encoded_get_byte_id(txt, pos); /*Convert to byte index instead of letter index*/
len = _lv_txt_encoded_get_byte_id(&txt[pos], len); len = _lv_txt_encoded_get_byte_id(&txt[pos], len);
@@ -861,7 +861,7 @@ static uint32_t lv_txt_iso8859_1_get_char_id(const char * txt, uint32_t byte_id)
*/ */
static uint32_t lv_txt_iso8859_1_get_length(const char * txt) static uint32_t lv_txt_iso8859_1_get_length(const char * txt)
{ {
return strlen(txt); return lv_strlen(txt);
} }
#else #else

View File

@@ -81,7 +81,7 @@ void lv_file_explorer_set_quick_access_path(lv_obj_t * obj, lv_file_explorer_dir
lv_file_explorer_t * explorer = (lv_file_explorer_t *)obj; lv_file_explorer_t * explorer = (lv_file_explorer_t *)obj;
/*If path is unavailable */ /*If path is unavailable */
if((path == NULL) || (strlen(path) <= 0)) return; if((path == NULL) || (lv_strlen(path) <= 0)) return;
char ** dir_str = NULL; char ** dir_str = NULL;
switch(dir) { switch(dir) {
@@ -116,14 +116,14 @@ void lv_file_explorer_set_quick_access_path(lv_obj_t * obj, lv_file_explorer_dir
} }
/*Get the size of the text*/ /*Get the size of the text*/
size_t len = strlen(path) + 1; size_t len = lv_strlen(path) + 1;
/*Allocate space for the new text*/ /*Allocate space for the new text*/
*dir_str = lv_malloc(len); *dir_str = lv_malloc(len);
LV_ASSERT_MALLOC(*dir_str); LV_ASSERT_MALLOC(*dir_str);
if(*dir_str == NULL) return; if(*dir_str == NULL) return;
strcpy(*dir_str, path); lv_strcpy(*dir_str, path);
} }
#endif #endif
@@ -498,7 +498,7 @@ static void browser_file_event_handler(lv_event_t * e)
str_fn = str_fn + 5; str_fn = str_fn + 5;
if((strcmp(str_fn, ".") == 0)) return; if((strcmp(str_fn, ".") == 0)) return;
if((strcmp(str_fn, "..") == 0) && (strlen(explorer->current_path) > 3)) { if((strcmp(str_fn, "..") == 0) && (lv_strlen(explorer->current_path) > 3)) {
strip_ext(explorer->current_path); strip_ext(explorer->current_path);
/*Remove the last '/' character*/ /*Remove the last '/' character*/
strip_ext(explorer->current_path); strip_ext(explorer->current_path);
@@ -559,7 +559,7 @@ static void show_dir(lv_obj_t * obj, const char * path)
} }
/*fn is empty, if not more files to read*/ /*fn is empty, if not more files to read*/
if(strlen(fn) == 0) { if(lv_strlen(fn) == 0) {
LV_LOG_USER("Not more files to read!"); LV_LOG_USER("Not more files to read!");
break; break;
} }
@@ -605,10 +605,10 @@ static void show_dir(lv_obj_t * obj, const char * path)
lv_obj_scroll_to_y(explorer->file_table, 0, LV_ANIM_OFF); lv_obj_scroll_to_y(explorer->file_table, 0, LV_ANIM_OFF);
lv_memzero(explorer->current_path, sizeof(explorer->current_path)); lv_memzero(explorer->current_path, sizeof(explorer->current_path));
strcpy(explorer->current_path, path); lv_strncpy(explorer->current_path, path, sizeof(explorer->current_path) - 1);
lv_label_set_text_fmt(explorer->path_label, LV_SYMBOL_EYE_OPEN" %s", path); lv_label_set_text_fmt(explorer->path_label, LV_SYMBOL_EYE_OPEN" %s", path);
size_t current_path_len = strlen(explorer->current_path); size_t current_path_len = lv_strlen(explorer->current_path);
if((*((explorer->current_path) + current_path_len) != '/') && (current_path_len < LV_FILE_EXPLORER_PATH_MAX_LEN)) { if((*((explorer->current_path) + current_path_len) != '/') && (current_path_len < LV_FILE_EXPLORER_PATH_MAX_LEN)) {
*((explorer->current_path) + current_path_len) = '/'; *((explorer->current_path) + current_path_len) = '/';
} }
@@ -618,7 +618,7 @@ static void show_dir(lv_obj_t * obj, const char * path)
/*Remove the specified suffix*/ /*Remove the specified suffix*/
static void strip_ext(char * dir) static void strip_ext(char * dir)
{ {
char * end = dir + strlen(dir); char * end = dir + lv_strlen(dir);
while(end >= dir && *end != '/') { while(end >= dir && *end != '/') {
--end; --end;
@@ -698,8 +698,8 @@ static bool is_end_with(const char * str1, const char * str2)
if(str1 == NULL || str2 == NULL) if(str1 == NULL || str2 == NULL)
return false; return false;
uint16_t len1 = strlen(str1); uint16_t len1 = lv_strlen(str1);
uint16_t len2 = strlen(str2); uint16_t len2 = lv_strlen(str2);
if((len1 < len2) || (len1 == 0 || len2 == 0)) if((len1 < len2) || (len1 == 0 || len2 == 0))
return false; return false;

View File

@@ -653,7 +653,7 @@ static void lv_ime_pinyin_kb_event(lv_event_t * e)
#if LV_IME_PINYIN_USE_K9_MODE #if LV_IME_PINYIN_USE_K9_MODE
if(pinyin_ime->mode == LV_IME_PINYIN_MODE_K9) { if(pinyin_ime->mode == LV_IME_PINYIN_MODE_K9) {
uint16_t tmp_btn_str_len = strlen(pinyin_ime->input_char); uint16_t tmp_btn_str_len = lv_strlen(pinyin_ime->input_char);
if((btn_id >= 16) && (tmp_btn_str_len > 0) && (btn_id < (16 + LV_IME_PINYIN_K9_CAND_TEXT_NUM))) { if((btn_id >= 16) && (tmp_btn_str_len > 0) && (btn_id < (16 + LV_IME_PINYIN_K9_CAND_TEXT_NUM))) {
lv_memzero(pinyin_ime->input_char, sizeof(pinyin_ime->input_char)); lv_memzero(pinyin_ime->input_char, sizeof(pinyin_ime->input_char));
strcat(pinyin_ime->input_char, txt); strcat(pinyin_ime->input_char, txt);
@@ -696,7 +696,7 @@ static void lv_ime_pinyin_kb_event(lv_event_t * e)
} }
#if LV_IME_PINYIN_USE_K9_MODE #if LV_IME_PINYIN_USE_K9_MODE
else if(pinyin_ime->mode == LV_IME_PINYIN_MODE_K9) { else if(pinyin_ime->mode == LV_IME_PINYIN_MODE_K9) {
pinyin_ime->k9_input_str_len = strlen(pinyin_ime->input_char) - 1; pinyin_ime->k9_input_str_len = lv_strlen(pinyin_ime->input_char) - 1;
pinyin_k9_get_legal_py(obj, pinyin_ime->k9_input_str, k9_py_map); pinyin_k9_get_legal_py(obj, pinyin_ime->k9_input_str, k9_py_map);
pinyin_k9_fill_cand(obj); pinyin_k9_fill_cand(obj);
pinyin_input_proc(obj); pinyin_input_proc(obj);
@@ -711,7 +711,7 @@ static void lv_ime_pinyin_kb_event(lv_event_t * e)
return; return;
} }
else if(strcmp(txt, "123") == 0) { else if(strcmp(txt, "123") == 0) {
for(uint16_t i = 0; i < strlen(txt); i++) for(uint16_t i = 0; i < lv_strlen(txt); i++)
lv_textarea_del_char(ta); lv_textarea_del_char(ta);
pinyin_ime_clear_data(obj); pinyin_ime_clear_data(obj);
@@ -743,8 +743,8 @@ static void lv_ime_pinyin_kb_event(lv_event_t * e)
else if((pinyin_ime->mode == LV_IME_PINYIN_MODE_K9) && (txt[0] >= 'a' && txt[0] <= 'z')) { else if((pinyin_ime->mode == LV_IME_PINYIN_MODE_K9) && (txt[0] >= 'a' && txt[0] <= 'z')) {
for(uint16_t i = 0; i < 8; i++) { for(uint16_t i = 0; i < 8; i++) {
if((strcmp(txt, k9_py_map[i]) == 0) || (strcmp(txt, "abc ") == 0)) { if((strcmp(txt, k9_py_map[i]) == 0) || (strcmp(txt, "abc ") == 0)) {
if(strcmp(txt, "abc ") == 0) pinyin_ime->k9_input_str_len += strlen(k9_py_map[i]) + 1; if(strcmp(txt, "abc ") == 0) pinyin_ime->k9_input_str_len += lv_strlen(k9_py_map[i]) + 1;
else pinyin_ime->k9_input_str_len += strlen(k9_py_map[i]); else pinyin_ime->k9_input_str_len += lv_strlen(k9_py_map[i]);
pinyin_ime->k9_input_str[pinyin_ime->ta_count] = 50 + i; pinyin_ime->k9_input_str[pinyin_ime->ta_count] = 50 + i;
break; break;
@@ -931,7 +931,7 @@ static char * pinyin_search_matching(lv_obj_t * obj, char * py_str, uint16_t * c
if(*py_str == 'v') return NULL; if(*py_str == 'v') return NULL;
offset = py_str[0] - 'a'; offset = py_str[0] - 'a';
len = strlen(py_str); len = lv_strlen(py_str);
cpHZ = &pinyin_ime->dict[pinyin_ime->py_pos[offset]]; cpHZ = &pinyin_ime->dict[pinyin_ime->py_pos[offset]];
count = pinyin_ime->py_num[offset]; count = pinyin_ime->py_num[offset];
@@ -946,7 +946,7 @@ static char * pinyin_search_matching(lv_obj_t * obj, char * py_str, uint16_t * c
// perfect match // perfect match
if(len == 1 || index == len) { if(len == 1 || index == len) {
// The Chinese character in UTF-8 encoding format is 3 bytes // The Chinese character in UTF-8 encoding format is 3 bytes
* cand_num = strlen((const char *)(cpHZ->py_mb)) / 3; * cand_num = lv_strlen((const char *)(cpHZ->py_mb)) / 3;
return (char *)(cpHZ->py_mb); return (char *)(cpHZ->py_mb);
} }
cpHZ++; cpHZ++;
@@ -965,8 +965,8 @@ static void pinyin_ime_clear_data(lv_obj_t * obj)
pinyin_ime->k9_legal_py_count = 0; pinyin_ime->k9_legal_py_count = 0;
lv_memzero(pinyin_ime->k9_input_str, LV_IME_PINYIN_K9_MAX_INPUT); lv_memzero(pinyin_ime->k9_input_str, LV_IME_PINYIN_K9_MAX_INPUT);
lv_memzero(lv_pinyin_k9_cand_str, sizeof(lv_pinyin_k9_cand_str)); lv_memzero(lv_pinyin_k9_cand_str, sizeof(lv_pinyin_k9_cand_str));
strcpy(lv_pinyin_k9_cand_str[LV_IME_PINYIN_K9_CAND_TEXT_NUM], LV_SYMBOL_RIGHT"\0"); lv_strcpy(lv_pinyin_k9_cand_str[LV_IME_PINYIN_K9_CAND_TEXT_NUM], LV_SYMBOL_RIGHT"\0");
strcpy(lv_pinyin_k9_cand_str[LV_IME_PINYIN_K9_CAND_TEXT_NUM + 1], "\0"); lv_strcpy(lv_pinyin_k9_cand_str[LV_IME_PINYIN_K9_CAND_TEXT_NUM + 1], "\0");
} }
#endif #endif
@@ -987,13 +987,13 @@ static void pinyin_k9_init_data(lv_obj_t * obj)
uint16_t btnm_i = 0; uint16_t btnm_i = 0;
for(btnm_i = 19; btnm_i < (LV_IME_PINYIN_K9_CAND_TEXT_NUM + 21); btnm_i++) { for(btnm_i = 19; btnm_i < (LV_IME_PINYIN_K9_CAND_TEXT_NUM + 21); btnm_i++) {
if(py_str_i == LV_IME_PINYIN_K9_CAND_TEXT_NUM) { if(py_str_i == LV_IME_PINYIN_K9_CAND_TEXT_NUM) {
strcpy(lv_pinyin_k9_cand_str[py_str_i], LV_SYMBOL_RIGHT"\0"); lv_strcpy(lv_pinyin_k9_cand_str[py_str_i], LV_SYMBOL_RIGHT"\0");
} }
else if(py_str_i == LV_IME_PINYIN_K9_CAND_TEXT_NUM + 1) { else if(py_str_i == LV_IME_PINYIN_K9_CAND_TEXT_NUM + 1) {
strcpy(lv_pinyin_k9_cand_str[py_str_i], "\0"); lv_strcpy(lv_pinyin_k9_cand_str[py_str_i], "\0");
} }
else { else {
strcpy(lv_pinyin_k9_cand_str[py_str_i], " \0"); lv_strcpy(lv_pinyin_k9_cand_str[py_str_i], " \0");
} }
lv_btnm_def_pinyin_k9_map[btnm_i] = lv_pinyin_k9_cand_str[py_str_i]; lv_btnm_def_pinyin_k9_map[btnm_i] = lv_pinyin_k9_cand_str[py_str_i];
@@ -1014,7 +1014,7 @@ static void pinyin_k9_get_legal_py(lv_obj_t * obj, char * k9_input, const char *
{ {
lv_ime_pinyin_t * pinyin_ime = (lv_ime_pinyin_t *)obj; lv_ime_pinyin_t * pinyin_ime = (lv_ime_pinyin_t *)obj;
uint16_t len = strlen(k9_input); uint16_t len = lv_strlen(k9_input);
if((len == 0) || (len >= LV_IME_PINYIN_K9_MAX_INPUT)) { if((len == 0) || (len >= LV_IME_PINYIN_K9_MAX_INPUT)) {
return; return;
@@ -1037,10 +1037,10 @@ static void pinyin_k9_get_legal_py(lv_obj_t * obj, char * k9_input, const char *
if(pinyin_k9_is_valid_py(obj, py_comp)) { if(pinyin_k9_is_valid_py(obj, py_comp)) {
if((count >= ll_len) || (ll_len == 0)) { if((count >= ll_len) || (ll_len == 0)) {
ll_index = _lv_ll_ins_tail(&pinyin_ime->k9_legal_py_ll); ll_index = _lv_ll_ins_tail(&pinyin_ime->k9_legal_py_ll);
strcpy(ll_index->py_str, py_comp); lv_strcpy(ll_index->py_str, py_comp);
} }
else if((count < ll_len)) { else if((count < ll_len)) {
strcpy(ll_index->py_str, py_comp); lv_strcpy(ll_index->py_str, py_comp);
ll_index = _lv_ll_get_next(&pinyin_ime->k9_legal_py_ll, ll_index); ll_index = _lv_ll_get_next(&pinyin_ime->k9_legal_py_ll, ll_index);
} }
count++; count++;
@@ -1049,7 +1049,7 @@ static void pinyin_k9_get_legal_py(lv_obj_t * obj, char * k9_input, const char *
} }
else { else {
flag = mark[index]; flag = mark[index];
if((size_t)flag < strlen(py9_map[k9_input[index] - '2'])) { if((size_t)flag < lv_strlen(py9_map[k9_input[index] - '2'])) {
py_comp[index] = py9_map[k9_input[index] - '2'][flag]; py_comp[index] = py9_map[k9_input[index] - '2'][flag];
mark[index] = mark[index] + 1; mark[index] = mark[index] + 1;
index++; index++;
@@ -1083,7 +1083,7 @@ static bool pinyin_k9_is_valid_py(lv_obj_t * obj, char * py_str)
if(*py_str == 'v') return false; if(*py_str == 'v') return false;
offset = py_str[0] - 'a'; offset = py_str[0] - 'a';
len = strlen(py_str); len = lv_strlen(py_str);
cpHZ = &pinyin_ime->dict[pinyin_ime->py_pos[offset]]; cpHZ = &pinyin_ime->dict[pinyin_ime->py_pos[offset]];
count = pinyin_ime->py_num[offset]; count = pinyin_ime->py_num[offset];
@@ -1117,19 +1117,19 @@ static void pinyin_k9_fill_cand(lv_obj_t * obj)
if(tmp_len != len) { if(tmp_len != len) {
lv_memzero(lv_pinyin_k9_cand_str, sizeof(lv_pinyin_k9_cand_str)); lv_memzero(lv_pinyin_k9_cand_str, sizeof(lv_pinyin_k9_cand_str));
strcpy(lv_pinyin_k9_cand_str[LV_IME_PINYIN_K9_CAND_TEXT_NUM], LV_SYMBOL_RIGHT"\0"); lv_strcpy(lv_pinyin_k9_cand_str[LV_IME_PINYIN_K9_CAND_TEXT_NUM], LV_SYMBOL_RIGHT"\0");
strcpy(lv_pinyin_k9_cand_str[LV_IME_PINYIN_K9_CAND_TEXT_NUM + 1], "\0"); lv_strcpy(lv_pinyin_k9_cand_str[LV_IME_PINYIN_K9_CAND_TEXT_NUM + 1], "\0");
len = tmp_len; len = tmp_len;
} }
ll_index = _lv_ll_get_head(&pinyin_ime->k9_legal_py_ll); ll_index = _lv_ll_get_head(&pinyin_ime->k9_legal_py_ll);
strcpy(pinyin_ime->input_char, ll_index->py_str); lv_strcpy(pinyin_ime->input_char, ll_index->py_str);
while(ll_index) { while(ll_index) {
if((index >= LV_IME_PINYIN_K9_CAND_TEXT_NUM) || \ if((index >= LV_IME_PINYIN_K9_CAND_TEXT_NUM) || \
(index >= pinyin_ime->k9_legal_py_count)) (index >= pinyin_ime->k9_legal_py_count))
break; break;
strcpy(lv_pinyin_k9_cand_str[index], ll_index->py_str); lv_strcpy(lv_pinyin_k9_cand_str[index], ll_index->py_str);
ll_index = _lv_ll_get_next(&pinyin_ime->k9_legal_py_ll, ll_index); /*Find the next list*/ ll_index = _lv_ll_get_next(&pinyin_ime->k9_legal_py_ll, ll_index); /*Find the next list*/
index++; index++;
} }
@@ -1139,7 +1139,7 @@ static void pinyin_k9_fill_cand(lv_obj_t * obj)
for(index = 0; index < pinyin_ime->k9_input_str_len; index++) { for(index = 0; index < pinyin_ime->k9_input_str_len; index++) {
lv_textarea_del_char(ta); lv_textarea_del_char(ta);
} }
pinyin_ime->k9_input_str_len = strlen(pinyin_ime->input_char); pinyin_ime->k9_input_str_len = lv_strlen(pinyin_ime->input_char);
lv_textarea_add_text(ta, pinyin_ime->input_char); lv_textarea_add_text(ta, pinyin_ime->input_char);
} }
@@ -1166,8 +1166,8 @@ static void pinyin_k9_cand_page_proc(lv_obj_t * obj, uint16_t dir)
if((NULL == ll_index) && (dir == 1)) return; if((NULL == ll_index) && (dir == 1)) return;
lv_memzero(lv_pinyin_k9_cand_str, sizeof(lv_pinyin_k9_cand_str)); lv_memzero(lv_pinyin_k9_cand_str, sizeof(lv_pinyin_k9_cand_str));
strcpy(lv_pinyin_k9_cand_str[LV_IME_PINYIN_K9_CAND_TEXT_NUM], LV_SYMBOL_RIGHT"\0"); lv_strcpy(lv_pinyin_k9_cand_str[LV_IME_PINYIN_K9_CAND_TEXT_NUM], LV_SYMBOL_RIGHT"\0");
strcpy(lv_pinyin_k9_cand_str[LV_IME_PINYIN_K9_CAND_TEXT_NUM + 1], "\0"); lv_strcpy(lv_pinyin_k9_cand_str[LV_IME_PINYIN_K9_CAND_TEXT_NUM + 1], "\0");
// next page // next page
if(dir == 1) { if(dir == 1) {
@@ -1176,7 +1176,7 @@ static void pinyin_k9_cand_page_proc(lv_obj_t * obj, uint16_t dir)
if(count >= (LV_IME_PINYIN_K9_CAND_TEXT_NUM - 1)) if(count >= (LV_IME_PINYIN_K9_CAND_TEXT_NUM - 1))
break; break;
strcpy(lv_pinyin_k9_cand_str[count], ll_index->py_str); lv_strcpy(lv_pinyin_k9_cand_str[count], ll_index->py_str);
ll_index = _lv_ll_get_next(&pinyin_ime->k9_legal_py_ll, ll_index); /*Find the next list*/ ll_index = _lv_ll_get_next(&pinyin_ime->k9_legal_py_ll, ll_index); /*Find the next list*/
count++; count++;
} }
@@ -1190,7 +1190,7 @@ static void pinyin_k9_cand_page_proc(lv_obj_t * obj, uint16_t dir)
while(ll_index) { while(ll_index) {
if(count < 0) break; if(count < 0) break;
strcpy(lv_pinyin_k9_cand_str[count], ll_index->py_str); lv_strcpy(lv_pinyin_k9_cand_str[count], ll_index->py_str);
ll_index = _lv_ll_get_prev(&pinyin_ime->k9_legal_py_ll, ll_index); /*Find the previous list*/ ll_index = _lv_ll_get_prev(&pinyin_ime->k9_legal_py_ll, ll_index); /*Find the previous list*/
count--; count--;
} }

View File

@@ -87,7 +87,7 @@ void lv_checkbox_set_text(lv_obj_t * obj, const char * txt)
#if LV_USE_ARABIC_PERSIAN_CHARS #if LV_USE_ARABIC_PERSIAN_CHARS
_lv_txt_ap_proc(txt, cb->txt); _lv_txt_ap_proc(txt, cb->txt);
#else #else
lv_strncpy(cb->txt, txt, len); lv_strcpy(cb->txt, txt);
#endif #endif
cb->static_txt = 0; cb->static_txt = 0;

View File

@@ -146,7 +146,7 @@ void lv_dropdown_set_options(lv_obj_t * obj, const char * options)
if(dropdown->options == NULL) return; if(dropdown->options == NULL) return;
#if LV_USE_ARABIC_PERSIAN_CHARS == 0 #if LV_USE_ARABIC_PERSIAN_CHARS == 0
lv_strncpy(dropdown->options, options, len); lv_strcpy(dropdown->options, options);
#else #else
_lv_txt_ap_proc(options, dropdown->options); _lv_txt_ap_proc(options, dropdown->options);
#endif #endif
@@ -203,7 +203,7 @@ void lv_dropdown_add_option(lv_obj_t * obj, const char * option, uint32_t pos)
LV_ASSERT_MALLOC(dropdown->options); LV_ASSERT_MALLOC(dropdown->options);
if(dropdown->options == NULL) return; if(dropdown->options == NULL) return;
lv_strncpy(dropdown->options, static_options, len); lv_strcpy(dropdown->options, static_options);
dropdown->static_txt = 0; dropdown->static_txt = 0;
} }
@@ -243,7 +243,7 @@ void lv_dropdown_add_option(lv_obj_t * obj, const char * option, uint32_t pos)
LV_ASSERT_MALLOC(ins_buf); LV_ASSERT_MALLOC(ins_buf);
if(ins_buf == NULL) return; if(ins_buf == NULL) return;
#if LV_USE_ARABIC_PERSIAN_CHARS == 0 #if LV_USE_ARABIC_PERSIAN_CHARS == 0
lv_strncpy(ins_buf, option, new_len + 1); lv_strcpy(ins_buf, option);
#else #else
_lv_txt_ap_proc(option, ins_buf); _lv_txt_ap_proc(option, ins_buf);
#endif #endif

View File

@@ -116,10 +116,10 @@ void lv_img_set_src(lv_obj_t * obj, const void * src)
if(img->src_type == LV_IMG_SRC_FILE || img->src_type == LV_IMG_SRC_SYMBOL) { if(img->src_type == LV_IMG_SRC_FILE || img->src_type == LV_IMG_SRC_SYMBOL) {
old_src = img->src; old_src = img->src;
} }
char * new_str = lv_malloc(strlen(src) + 1); char * new_str = lv_malloc(lv_strlen(src) + 1);
LV_ASSERT_MALLOC(new_str); LV_ASSERT_MALLOC(new_str);
if(new_str == NULL) return; if(new_str == NULL) return;
strcpy(new_str, src); lv_strcpy(new_str, src);
img->src = new_str; img->src = new_str;
if(old_src) lv_free((void *)old_src); if(old_src) lv_free((void *)old_src);

View File

@@ -1281,8 +1281,7 @@ static void copy_text_to_label(lv_label_t * label, const char * text)
#if LV_USE_ARABIC_PERSIAN_CHARS #if LV_USE_ARABIC_PERSIAN_CHARS
_lv_txt_ap_proc(text, label->text); _lv_txt_ap_proc(text, label->text);
#else #else
size_t len = lv_strlen(text) + 1; lv_strcpy(label->text, text);
lv_memcpy(label->text, text, len);
#endif #endif
} }

View File

@@ -400,7 +400,7 @@ void lv_menu_set_page_title(lv_obj_t * page_obj, char const * const title)
if(page->title == NULL) { if(page->title == NULL) {
return; return;
} }
lv_strncpy(page->title, title, len); lv_strcpy(page->title, title);
} }
else { else {
page->title = NULL; page->title = NULL;

View File

@@ -130,7 +130,7 @@ void lv_roller_set_options(lv_obj_t * obj, const char * options, lv_roller_mode_
char * opt_extra = lv_malloc(opt_len * roller->inf_page_cnt); char * opt_extra = lv_malloc(opt_len * roller->inf_page_cnt);
uint8_t i; uint8_t i;
for(i = 0; i < roller->inf_page_cnt; i++) { for(i = 0; i < roller->inf_page_cnt; i++) {
lv_strncpy(&opt_extra[opt_len * i], options, opt_len); lv_strcpy(&opt_extra[opt_len * i], options);
opt_extra[opt_len * (i + 1) - 1] = '\n'; opt_extra[opt_len * (i + 1) - 1] = '\n';
} }
opt_extra[opt_len * roller->inf_page_cnt - 1] = '\0'; opt_extra[opt_len * roller->inf_page_cnt - 1] = '\0';

View File

@@ -164,7 +164,7 @@ void lv_span_set_text(lv_span_t * span, const char * text)
if(span->txt == NULL) return; if(span->txt == NULL) return;
span->static_flag = 0; span->static_flag = 0;
lv_strncpy(span->txt, text, text_alloc_len); lv_strcpy(span->txt, text);
refresh_self_size(span->spangroup); refresh_self_size(span->spangroup);
} }

View File

@@ -971,8 +971,7 @@ static void copy_cell_txt(char * dst, const char * txt)
#if LV_USE_ARABIC_PERSIAN_CHARS #if LV_USE_ARABIC_PERSIAN_CHARS
_lv_txt_ap_proc(txt, &dst[1]); _lv_txt_ap_proc(txt, &dst[1]);
#else #else
size_t len = lv_strlen(txt) + 1; lv_strcpy(&dst[1], txt);
lv_memcpy(&dst[1], txt, len);
#endif #endif
} }

View File

@@ -86,7 +86,8 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * obj, const char * name)
lv_memcpy(new_map, old_map, sizeof(const char *) * (tab_id - 1)); lv_memcpy(new_map, old_map, sizeof(const char *) * (tab_id - 1));
size_t len = lv_strlen(name) + 1; size_t len = lv_strlen(name) + 1;
new_map[tab_id - 1] = lv_malloc(len); new_map[tab_id - 1] = lv_malloc(len);
lv_strncpy((char *)new_map[tab_id - 1], name, len); LV_ASSERT_MALLOC(new_map[tab_id - 1]);
lv_strcpy((char *)new_map[tab_id - 1], name);
new_map[tab_id] = (char *)""; new_map[tab_id] = (char *)"";
} }
/*left or right dir*/ /*left or right dir*/
@@ -96,7 +97,8 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * obj, const char * name)
if(tabview->tab_cnt == 0) { if(tabview->tab_cnt == 0) {
size_t len = lv_strlen(name) + 1; size_t len = lv_strlen(name) + 1;
new_map[0] = lv_malloc(len); new_map[0] = lv_malloc(len);
lv_strncpy((char *)new_map[0], name, len); LV_ASSERT_MALLOC(new_map[0]);
lv_strcpy((char *)new_map[0], name);
new_map[1] = (char *)""; new_map[1] = (char *)"";
} }
else { else {
@@ -104,7 +106,7 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * obj, const char * name)
new_map[tab_id * 2 - 3] = (char *)"\n"; new_map[tab_id * 2 - 3] = (char *)"\n";
new_map[tab_id * 2 - 2] = lv_malloc(len); new_map[tab_id * 2 - 2] = lv_malloc(len);
new_map[tab_id * 2 - 1] = (char *)""; new_map[tab_id * 2 - 1] = (char *)"";
lv_strncpy((char *)new_map[(tab_id * 2) - 2], name, len); lv_strcpy((char *)new_map[(tab_id * 2) - 2], name);
} }
} }
tabview->map = new_map; tabview->map = new_map;
@@ -135,7 +137,8 @@ void lv_tabview_rename_tab(lv_obj_t * obj, uint32_t id, const char * new_name)
lv_free(tabview->map[id]); lv_free(tabview->map[id]);
size_t len = lv_strlen(new_name) + 1; size_t len = lv_strlen(new_name) + 1;
tabview->map[id] = lv_malloc(len); tabview->map[id] = lv_malloc(len);
lv_strncpy(tabview->map[id], new_name, len); LV_ASSERT_MALLOC(tabview->map[id]);
lv_strcpy(tabview->map[id], new_name);
lv_obj_invalidate(obj); lv_obj_invalidate(obj);
} }

View File

@@ -304,7 +304,7 @@ void lv_textarea_set_text(lv_obj_t * obj, const char * txt)
ta->pwd_tmp = lv_realloc(ta->pwd_tmp, len); ta->pwd_tmp = lv_realloc(ta->pwd_tmp, len);
LV_ASSERT_MALLOC(ta->pwd_tmp); LV_ASSERT_MALLOC(ta->pwd_tmp);
if(ta->pwd_tmp == NULL) return; if(ta->pwd_tmp == NULL) return;
lv_strncpy(ta->pwd_tmp, txt, len); lv_strcpy(ta->pwd_tmp, txt);
/*Auto hide characters*/ /*Auto hide characters*/
auto_hide_characters(obj); auto_hide_characters(obj);
@@ -335,7 +335,7 @@ void lv_textarea_set_placeholder_text(lv_obj_t * obj, const char * txt)
return; return;
} }
lv_strncpy(ta->placeholder_txt, txt, txt_len + 1); lv_strcpy(ta->placeholder_txt, txt);
ta->placeholder_txt[txt_len] = '\0'; ta->placeholder_txt[txt_len] = '\0';
} }
@@ -419,7 +419,7 @@ void lv_textarea_set_password_mode(lv_obj_t * obj, bool en)
LV_ASSERT_MALLOC(ta->pwd_tmp); LV_ASSERT_MALLOC(ta->pwd_tmp);
if(ta->pwd_tmp == NULL) return; if(ta->pwd_tmp == NULL) return;
lv_strncpy(ta->pwd_tmp, txt, len + 1); lv_strcpy(ta->pwd_tmp, txt);
pwd_char_hider(obj); pwd_char_hider(obj);
@@ -459,7 +459,7 @@ void lv_textarea_set_password_bullet(lv_obj_t * obj, const char * bullet)
return; return;
} }
lv_strncpy(ta->pwd_bullet, bullet, txt_len + 1); lv_strcpy(ta->pwd_bullet, bullet);
ta->pwd_bullet[txt_len] = '\0'; ta->pwd_bullet[txt_len] = '\0';
} }