cubecart / v6

CubeCart Version 6
https://cubecart.com
71 stars 58 forks source link

Code Check: Divide by Zero #3602

Closed bhsmither closed 1 month ago

bhsmither commented 1 month ago

Similar to #3506, code needs to be reviewed in statistics.index.inc.php where the result from DB->query() could result in a zero value - however improbable that could be.

Near lines 177-178 could be combined to:

        $result['percent'] = (float)$divider[0]['totalProducts'] ? number_format(100*($result['quan']/$divider[0]['totalProducts']),2) : 0;

Near lines 212-214 could be combined to:

        $result['percent'] = (float)$divider[0]['totalHits'] ? number_format(100*($result['popularity']/$divider[0]['totalHits']),2) : 0;
        // not used // $max_percent = ($result['percent']>$max_percent) ? $result['percent'] : $max_percent;

Near lines 246-248 could be combined to:

        $result['percent']  = (float)$divider[0]['totalHits'] ? number_format(100*($result['hits']/$divider[0]['totalHits']),2) : 0;
        // not used // $max_percent = ($result['percent']>$max_percent) ? $result['percent'] : $max_percent;
abrookbanks commented 1 month ago

Fantastic. Thanks.