Skip to content

Commit e2d8cb3

Browse files
committed
improve call path_build
1 parent 1ca2ddb commit e2d8cb3

File tree

5 files changed

+35
-26
lines changed

5 files changed

+35
-26
lines changed

docs/changes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 最新动态
22

3+
2025/08/21
4+
* 添加对path相关函数返回值的处理,避免诸如路径过长导致死循环的问题(感谢朝泽提供补丁)
5+
36
2025/08/20
47
* 修复demouiold崩溃问题(感谢兆坤提供补丁)
58
* 修复list_view中的item使用self_layout时布局异常的问题(感谢俊杰提供补丁)

src/base/assets_manager.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,18 +1027,22 @@ assets_manager_t* assets_managers_ref(const char* name) {
10271027
uint32_t i = 0;
10281028
const char* iter = NULL;
10291029
char res_root[MAX_PATH + 1] = {0};
1030-
am = assets_manager_create(5);
1031-
return_value_if_fail(am != NULL, NULL);
1030+
bool_t applet_res_root_found = FALSE;
1031+
return_value_if_fail(assets_managers_is_applet_assets_supported(), NULL);
10321032

1033-
if (s_applet_res_roots != NULL) {
1034-
for (i = 0; i < s_applet_res_roots->size; i++) {
1035-
iter = (const char*)darray_get(s_applet_res_roots, i);
1036-
path_build(res_root, MAX_PATH, iter, name, NULL);
1033+
for (i = 0; i < s_applet_res_roots->size; i++) {
1034+
iter = (const char*)darray_get(s_applet_res_roots, i);
1035+
if (path_build(res_root, MAX_PATH, iter, name, NULL) == RET_OK) {
10371036
if (fs_dir_exist(os_fs(), res_root)) {
1037+
applet_res_root_found = TRUE;
10381038
break;
10391039
}
10401040
}
10411041
}
1042+
return_value_if_fail(applet_res_root_found, NULL);
1043+
1044+
am = assets_manager_create(5);
1045+
return_value_if_fail(am != NULL, NULL);
10421046
am->name = tk_strdup(name);
10431047
darray_push(s_assets_managers, am);
10441048
assets_manager_set_res_root(am, res_root);

src/conf_io/app_conf_init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ static ret_t app_conf_get_url(char url[MAX_PATH + 1], const char* app_name, cons
4343
return_value_if_fail(fs_create_dir(fs, path) == RET_OK, RET_FAIL);
4444
}
4545

46-
path_build(app_dir, MAX_PATH, path, app_name, NULL);
46+
return_value_if_fail(path_build(app_dir, MAX_PATH, path, app_name, NULL) == RET_OK, RET_FAIL);
4747
if (!path_exist(app_dir)) {
4848
return_value_if_fail(fs_create_dir(fs, app_dir) == RET_OK, RET_FAIL);
4949
}
5050

5151
tk_snprintf(url, MAX_PATH, "app_conf.%s", extname);
52-
path_build(path, MAX_PATH, app_dir, url, NULL);
52+
return_value_if_fail(path_build(path, MAX_PATH, app_dir, url, NULL) == RET_OK, RET_FAIL);
5353
tk_snprintf(url, MAX_PATH, "file://%s", path);
5454

5555
return RET_OK;

src/tkc/fs.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ ret_t fs_remove_dir_r(fs_t* fs, const char* name) {
575575
continue;
576576
} else {
577577
char subname[MAX_PATH + 1];
578-
path_build(subname, MAX_PATH, name, item.name, NULL);
578+
break_if_fail(path_build(subname, MAX_PATH, name, item.name, NULL));
579579
if (item.is_dir) {
580580
ret = fs_remove_dir_r(fs, subname);
581581
} else {
@@ -717,8 +717,10 @@ static ret_t fs_copy_item(fs_t* fs, fs_item_t* item, const char* src, const char
717717
bool_t overwrite) {
718718
char subsrc[MAX_PATH + 1];
719719
char subdst[MAX_PATH + 1];
720-
path_build(subsrc, MAX_PATH, src, item->name, NULL);
721-
path_build(subdst, MAX_PATH, dst, item->name, NULL);
720+
return_value_if_fail(path_build(subsrc, MAX_PATH, src, item->name, NULL) == RET_OK,
721+
RET_BAD_PARAMS);
722+
return_value_if_fail(path_build(subdst, MAX_PATH, dst, item->name, NULL) == RET_OK,
723+
RET_BAD_PARAMS);
722724

723725
if (!fs_dir_exist(fs, dst)) {
724726
return_value_if_fail(fs_create_dir_r(fs, dst) == RET_OK, RET_IO);
@@ -794,7 +796,8 @@ ret_t fs_foreach(const char* path, int depth, tk_visit_t on_file, tk_visit_t on_
794796
continue;
795797
}
796798

797-
path_build(filename, MAX_PATH, path, item.name, NULL);
799+
break_if_fail(path_build(filename, MAX_PATH, path, item.name, NULL) == RET_OK);
800+
798801
if (item.is_reg_file) {
799802
if (on_file != NULL && on_file(ctx, filename) != RET_OK) {
800803
break;

src/tkc/path.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ ret_t path_app_root(char path[MAX_PATH + 1]) {
151151
memset(exe_path, 0x00, sizeof(exe_path));
152152

153153
if (fs_get_exe(os_fs(), exe_path) == RET_OK) {
154-
path_normalize(exe_path, path, MAX_PATH + 1);
154+
return_value_if_fail(path_normalize(exe_path, path, MAX_PATH + 1) == RET_OK, RET_FAIL);
155155
p = strrchr(path, TK_PATH_SEP);
156156
if (p != NULL) {
157157
*p = '\0';
@@ -308,8 +308,8 @@ ret_t path_replace_basename(char* result, int32_t size, const char* filename,
308308
char dirname[MAX_PATH + 1];
309309
return_value_if_fail(result != NULL && filename != NULL && basename != NULL, RET_BAD_PARAMS);
310310

311-
path_normalize(filename, result, size);
312-
path_dirname(result, dirname, MAX_PATH);
311+
return_value_if_fail(path_normalize(filename, result, size) == RET_OK, RET_FAIL);
312+
return_value_if_fail(path_dirname(result, dirname, MAX_PATH) == RET_OK, RET_FAIL);
313313

314314
dirname[MAX_PATH] = '\0';
315315
return path_build(result, size, dirname, basename, NULL);
@@ -320,7 +320,7 @@ ret_t path_replace_extname(char* result, int32_t size, const char* filename, con
320320
return_value_if_fail(result != NULL && filename != NULL && extname != NULL, RET_BAD_PARAMS);
321321

322322
memset(result, 0x00, size);
323-
path_normalize(filename, result, size);
323+
return_value_if_fail(path_normalize(filename, result, size) == RET_OK, RET_FAIL);
324324
p = strrchr(result, '.');
325325
if (p != NULL) {
326326
uint32_t n = 0;
@@ -354,17 +354,15 @@ ret_t path_app_root_ex(char path[MAX_PATH + 1], const char* subpath) {
354354
char app_root[MAX_PATH + 1] = {0};
355355
return_value_if_fail(path_app_root(app_root) == RET_OK, RET_BAD_PARAMS);
356356

357-
path_build(path, MAX_PATH, app_root, subpath, NULL);
358-
359-
return RET_OK;
357+
return path_build(path, MAX_PATH, app_root, subpath, NULL);
360358
}
361359

362360
const char* path_prepend_app_root(char full_path[MAX_PATH + 1], const char* path) {
363361
char app_root[MAX_PATH + 1] = {0};
364362
return_value_if_fail(path != NULL, NULL);
365363
return_value_if_fail(path_app_root(app_root) == RET_OK, NULL);
366364

367-
path_build(full_path, MAX_PATH, app_root, path, NULL);
365+
return_value_if_fail(path_build(full_path, MAX_PATH, app_root, path, NULL) == RET_OK, NULL);
368366

369367
return full_path;
370368
}
@@ -374,7 +372,7 @@ const char* path_prepend_temp_path(char full_path[MAX_PATH + 1], const char* pat
374372
return_value_if_fail(path != NULL, NULL);
375373
return_value_if_fail(fs_get_temp_path(os_fs(), temp_path) == RET_OK, NULL);
376374

377-
path_build(full_path, MAX_PATH, temp_path, path, NULL);
375+
return_value_if_fail(path_build(full_path, MAX_PATH, temp_path, path, NULL) == RET_OK, NULL);
378376

379377
return full_path;
380378
}
@@ -384,7 +382,8 @@ const char* path_prepend_user_storage_path(char full_path[MAX_PATH + 1], const c
384382
return_value_if_fail(path != NULL, NULL);
385383
return_value_if_fail(fs_get_user_storage_path(os_fs(), user_storage_path) == RET_OK, NULL);
386384

387-
path_build(full_path, MAX_PATH, user_storage_path, path, NULL);
385+
return_value_if_fail(path_build(full_path, MAX_PATH, user_storage_path, path, NULL) == RET_OK,
386+
NULL);
388387

389388
return full_path;
390389
}
@@ -393,7 +392,7 @@ ret_t path_abs_normalize(const char* filename, char* result, int32_t size) {
393392
char path[MAX_PATH + 1];
394393
return_value_if_fail(filename != NULL && result != NULL && size > 0, RET_BAD_PARAMS);
395394

396-
path_abs(filename, path, MAX_PATH);
395+
return_value_if_fail(path_abs(filename, path, MAX_PATH) == RET_OK, RET_FAIL);
397396
return path_normalize(path, result, size);
398397
}
399398

@@ -403,10 +402,10 @@ const char* path_abs_normalize_with_root(const char* root, const char* rel_filen
403402
char abs_root[MAX_PATH + 1];
404403
return_value_if_fail(root != NULL && rel_filename != NULL, NULL);
405404

406-
path_abs_normalize(root, abs_root, MAX_PATH);
405+
return_value_if_fail(path_abs_normalize(root, abs_root, MAX_PATH) == RET_OK, NULL);
407406

408-
path_build(path, MAX_PATH, abs_root, rel_filename, NULL);
409-
path_normalize(path, filename, MAX_PATH);
407+
return_value_if_fail(path_build(path, MAX_PATH, abs_root, rel_filename, NULL) == RET_OK, NULL);
408+
return_value_if_fail(path_normalize(path, filename, MAX_PATH) == RET_OK, NULL);
410409

411410
if (strncmp(filename, abs_root, strlen(abs_root)) == 0) {
412411
return filename;

0 commit comments

Comments
 (0)