Skip to content
Open
Changes from all commits
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
8 changes: 7 additions & 1 deletion common/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void init_fe_bgm(int *fe_bgm, int bgm_type, int re_init) {
}

size_t capacity = 8;
bgm_files = malloc(capacity * sizeof(char *));
bgm_files = calloc(capacity, sizeof(char *));
if (!bgm_files) {
LOG_ERROR("audio", "%s", lang.system.fail_allocate_mem);
closedir(dir);
Expand All @@ -239,6 +239,12 @@ void init_fe_bgm(int *fe_bgm, int bgm_type, int re_init) {
if (bgm_file_count >= capacity) {
capacity <<= 1;

if (capacity > SIZE_MAX / sizeof(char *)) {
LOG_ERROR("audio", "%s", lang.system.fail_allocate_mem);
closedir(dir);
return;
}

char **bgm_temp = realloc(bgm_files, capacity * sizeof(char *));

if (!bgm_temp) {
Expand Down