Skip to content

Commit 7f32711

Browse files
committed
fix possible div by 0 in core count detection
1 parent 1e71c03 commit 7f32711

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

misrc_tools/misrc_capture.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,13 @@ int main(int argc, char **argv)
462462
#if LIBFLAC_ENABLED == 1 && defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT >= 14
463463
if (flac_threads == 0) {
464464
int out_cnt = ((output_names[0] == NULL) ? 0 : 1) + ((output_names[1] == NULL) ? 0 : 1);
465-
flac_threads = get_num_cores();
466-
fprintf(stderr,"Detected %d cores in the system available to the process\n",flac_threads);
467-
flac_threads = (flac_threads - 2 - out_cnt) / out_cnt;
468-
if (flac_threads == 0) flac_threads = 1;
469-
if (flac_threads > 128) flac_threads = 128;
465+
if (out_cnt != 0) {
466+
flac_threads = get_num_cores();
467+
fprintf(stderr,"Detected %d cores in the system available to the process\n",flac_threads);
468+
flac_threads = (flac_threads - 2 - out_cnt) / out_cnt;
469+
if (flac_threads == 0) flac_threads = 1;
470+
if (flac_threads > 128) flac_threads = 128;
471+
}
470472
}
471473
#endif
472474

0 commit comments

Comments
 (0)