From e71d457af923f373505729fe5a335e6768f6144a Mon Sep 17 00:00:00 2001 From: Marshall Mohror Date: Wed, 6 Jul 2022 13:00:00 -0500 Subject: [PATCH] guard against div-by-zero --- src/common/x64/cpu_detect.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/common/x64/cpu_detect.cpp b/src/common/x64/cpu_detect.cpp index 4230b2da6f..1a27532d45 100644 --- a/src/common/x64/cpu_detect.cpp +++ b/src/common/x64/cpu_detect.cpp @@ -170,8 +170,11 @@ static CPUCaps Detect() { // The CPU model can be detected to use the values from turbostat // https://github.com/torvalds/linux/blob/master/tools/power/x86/turbostat/turbostat.c#L5569 // but it's easier to just estimate the TSC tick rate for these cases. - caps.tsc_frequency = static_cast(caps.crystal_frequency) * - caps.tsc_crystal_ratio_numerator / caps.tsc_crystal_ratio_denominator; + if (caps.tsc_crystal_ratio_denominator) { + caps.tsc_frequency = static_cast(caps.crystal_frequency) * + caps.tsc_crystal_ratio_numerator / + caps.tsc_crystal_ratio_denominator; + } } if (max_std_fn >= 0x16) {