From c73044c0c33d93f0b6092d8c0cfb46c6f8805a26 Mon Sep 17 00:00:00 2001 From: Zack Galbreath Date: Fri, 17 May 2024 10:56:14 -0400 Subject: [PATCH] Catch DivisionByZeroError on index.php (#2211) Fixes #2204 --- app/cdash/public/api/v1/index.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/cdash/public/api/v1/index.php b/app/cdash/public/api/v1/index.php index 32df9c2419..9d49377f02 100644 --- a/app/cdash/public/api/v1/index.php +++ b/app/cdash/public/api/v1/index.php @@ -412,11 +412,15 @@ if ((int) $build_array['loctesteddiff'] > 0) { $loctesteddiff = (int) $build_array['loctesteddiff']; $locuntesteddiff = (int) $build_array['locuntesteddiff']; - @$previouspercent = - round(($loctested - $loctesteddiff) / - ($loctested - $loctesteddiff + - $locuntested - $locuntesteddiff) - * 100, 2); + try { + $previouspercent = + round(($loctested - $loctesteddiff) / + ($loctested - $loctesteddiff + + $locuntested - $locuntesteddiff) + * 100, 2); + } catch (\DivisionByZeroError $e) { + $previouspercent = 0; + } $percentdiff = round($percent - $previouspercent, 2); $coverage_response['percentagediff'] = $percentdiff; $coverage_response['locuntesteddiff'] = $locuntesteddiff;