Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the error caused by recursion in read_content function (AEGHB-773) #395

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions examples/hmi/mp3_example/main/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
herexiong marked this conversation as resolved.
Show resolved Hide resolved
DIR *dir = opendir(path);
while (1) {
de = readdir(dir);
Expand All @@ -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
Expand Down