From cb0f9f1e159ac198e1d7338fb6ce021d0a0c1abd Mon Sep 17 00:00:00 2001 From: lixianjing Date: Wed, 4 Sep 2024 18:09:20 +0800 Subject: [PATCH] improve call tk_strncpy_s --- docs/changes.md | 1 + src/base/theme_xml.inc | 6 +++--- src/base/ui_loader.c | 2 +- src/base/widget.c | 2 +- src/debugger/debugger_server.c | 4 ++-- src/tkc/fscript.c | 4 ++-- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index b7667188a..5388e4626 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -2,6 +2,7 @@ 2024/09/04 * 完善event\_from\_name(感谢兆坤提供补丁) + * 修复tk_strncpy_s用法(感谢颖健提供补丁) 2024/08/29 * 修改tk_client支持修改读写超时(感谢智明提供补丁) diff --git a/src/base/theme_xml.inc b/src/base/theme_xml.inc index 20ad1b150..5efbea848 100644 --- a/src/base/theme_xml.inc +++ b/src/base/theme_xml.inc @@ -156,9 +156,9 @@ static void xml_gen_on_state_end(XmlBuilder* thiz) { tk_object_copy_props(style, b->state_style, TRUE); item.offset = 0; - tk_strncpy_s(item.name, sizeof(item.name) - 1, b->style_name, tk_strlen(b->style_name)); - tk_strncpy_s(item.state, sizeof(item.state) - 1, b->state_name, tk_strlen(b->state_name)); - tk_strncpy_s(item.widget_type, sizeof(item.widget_type) - 1, b->widget_type, + tk_strncpy_s(item.name, sizeof(item.name), b->style_name, tk_strlen(b->style_name)); + tk_strncpy_s(item.state, sizeof(item.state), b->state_name, tk_strlen(b->state_name)); + tk_strncpy_s(item.widget_type, sizeof(item.widget_type), b->widget_type, tk_strlen(b->widget_type)); if (darray_push(&(b->styles), style) == RET_OK) { diff --git a/src/base/ui_loader.c b/src/base/ui_loader.c index 6f362977b..ee8c74120 100644 --- a/src/base/ui_loader.c +++ b/src/base/ui_loader.c @@ -49,7 +49,7 @@ widget_t* ui_loader_load_widget_with_parent(const char* name, widget_t* parent) assets_managers_is_applet_assets_supported()) { const char* p = strchr(name, '.'); if (p != NULL) { - tk_strncpy_s(applet_name, sizeof(applet_name) - 1, name, p - name); + tk_strncpy_s(applet_name, sizeof(applet_name), name, p - name); am = assets_managers_ref(applet_name); name = p + 1; } diff --git a/src/base/widget.c b/src/base/widget.c index 018653704..2abe95164 100644 --- a/src/base/widget.c +++ b/src/base/widget.c @@ -5287,7 +5287,7 @@ ret_t widget_set_props(widget_t* widget, const char* params) { tokenizer_init(&t, params, strlen(params), "&="); while (tokenizer_has_more(&t)) { k = tokenizer_next(&t); - tk_strncpy_s(key, sizeof(key) - 1, k, tk_strlen(k)); + tk_strncpy_s(key, sizeof(key), k, tk_strlen(k)); k = key; v = tokenizer_next(&t); diff --git a/src/debugger/debugger_server.c b/src/debugger/debugger_server.c index 3d1edd7d9..323ec6295 100644 --- a/src/debugger/debugger_server.c +++ b/src/debugger/debugger_server.c @@ -389,7 +389,7 @@ static ret_t debugger_server_attach_debugger(debugger_server_t* server, const ch code_id = strchr(arg, ':'); return_value_if_fail(code_id != NULL, RET_BAD_PARAMS); - tk_strncpy_s(lang, TK_NAME_LEN, arg, code_id - arg); + tk_strncpy_s(lang, sizeof(lang), arg, code_id - arg); code_id++; if (server->single_mode) { @@ -407,7 +407,7 @@ static ret_t debugger_server_launch_debugger(debugger_server_t* server, binary_d code = strchr((char*)(arg->data), ':'); return_value_if_fail(code != NULL, RET_BAD_PARAMS); - tk_strncpy_s(lang, TK_NAME_LEN, (char*)(arg->data), code - (char*)(arg->data)); + tk_strncpy_s(lang, sizeof(lang), (char*)(arg->data), code - (char*)(arg->data)); code++; if (tk_mutex_nest_lock(server->mutex) == RET_OK) { binary_data_t data; diff --git a/src/tkc/fscript.c b/src/tkc/fscript.c index 2c6f6434f..a6e30e57a 100644 --- a/src/tkc/fscript.c +++ b/src/tkc/fscript.c @@ -1421,7 +1421,7 @@ static ret_t fscript_parser_unget_token(fscript_parser_t* parser) { static ret_t token_to_value(fscript_parser_t* parser, token_t* t, value_t* v) { if (t->type == TOKEN_NUMBER) { char number[64]; - tk_strncpy_s(number, sizeof(number) - 1, t->token, t->size); + tk_strncpy_s(number, sizeof(number), t->token, t->size); if (strchr(number, '.') != NULL) { value_set_double(v, tk_atof(number)); } else { @@ -1470,7 +1470,7 @@ static ret_t token_to_value(fscript_parser_t* parser, token_t* t, value_t* v) { p = strchr(name, '.'); if (p != NULL) { char first_name[TK_NAME_LEN + 1]; - tk_strncpy_s(first_name, TK_NAME_LEN, name, p - name); + tk_strncpy_s(first_name, sizeof(first_name), name, p - name); value_id_suboffset(v) = p - name + 1; value_id_index(v) = darray_find_index(parser->symbols, (void*)first_name); } else {