From e21de6cf4298d2c2f2c3546b7e24cfa7f28789ff Mon Sep 17 00:00:00 2001 From: herexiong Date: Sat, 10 Aug 2024 17:16:58 +0800 Subject: [PATCH 1/2] Fix the error caused by recursion in read_content function --- examples/hmi/mp3_example/main/app_main.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/hmi/mp3_example/main/app_main.c b/examples/hmi/mp3_example/main/app_main.c index 03ce29e6b..40ae70939 100644 --- a/examples/hmi/mp3_example/main/app_main.c +++ b/examples/hmi/mp3_example/main/app_main.c @@ -375,11 +375,12 @@ static void sdmmc_init() sdmmc_card_print_info(stdout, card); } -static void read_content(const char *path, uint8_t *filecount) +static int read_content(const char *path, uint8_t *filecount) { + uint8_t ret = 0; char nextpath[100]; struct dirent *de; - *filecount = 0; + // *filecount = 0; DIR *dir = opendir(path); while (1) { de = readdir(dir); @@ -389,16 +390,21 @@ static void read_content(const char *path, uint8_t *filecount) if (strstr(de->d_name, ".mp3") || strstr(de->d_name, ".MP3")) { sprintf(directory[*filecount], "%s/%s", path, de->d_name); printf("%s\n", directory[*filecount]); - if ((*filecount)++ >= MAX_PLAY_FILE_NUM) { + if (++(*filecount) >= MAX_PLAY_FILE_NUM) { + ret = -1; break; } } } else if (de->d_type == DT_DIR) { sprintf(nextpath, "%s/%s", path, de->d_name); - read_content(nextpath, filecount); + ret = read_content(nextpath, filecount); + if(ret == -1){ + break; + } } } closedir(dir); + return ret; } #if USE_ADF_TO_PLAY From c92661cfa5eb27baeed98e2e8780aa30b44f5c62 Mon Sep 17 00:00:00 2001 From: herexiong <80973703+herexiong@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:55:32 +0800 Subject: [PATCH 2/2] Update examples/hmi/mp3_example/main/app_main.c Co-authored-by: leeebo --- examples/hmi/mp3_example/main/app_main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/hmi/mp3_example/main/app_main.c b/examples/hmi/mp3_example/main/app_main.c index 40ae70939..397fb8cca 100644 --- a/examples/hmi/mp3_example/main/app_main.c +++ b/examples/hmi/mp3_example/main/app_main.c @@ -380,7 +380,6 @@ static int read_content(const char *path, uint8_t *filecount) uint8_t ret = 0; char nextpath[100]; struct dirent *de; - // *filecount = 0; DIR *dir = opendir(path); while (1) { de = readdir(dir);