Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
concerning function _chart_adjust_resolution($chart_id, &$data, $max_value = NULL)
if $max[$chart_id] is 0, a division by zero error is thrown
attached patch solves this by changing this
if ($max[$chart_id] > $resoluton){
$divider = round($max[$chart_id] / $resoluton, 1);
}
else {
$multiplier = round($resoluton / $max[$chart_id], 1);
}
into this
if ($max[$chart_id] > $resoluton){
$divider = round($max[$chart_id] / $resoluton, 1);
}
elseif ($max[$chart_id] != 0) {
$multiplier = round($resoluton / $max[$chart_id], 1);
}
should apply to HEAD
Comment | File | Size | Author |
---|---|---|---|
#11 | divison_by_zero-594202.txt | 419 bytes | ximo |
#8 | chart-division-by-zero-594202.patch | 467 bytes | mstef |
#5 | chart-fix-division-by-zero.patch | 486 bytes | mstef |
chart-division-by-zero.patch | 554 bytes | seutje |
Comments
Comment #1
seutje CreditAttribution: seutje commentedBy the way, I got this error in combination with the google analytics API module, not sure if this is chart API's fault for not catching it, or google analytics API's fault for calling a function with improper values
-> #551146: Division by zero error when viewing a report and bounce rate is zero
Comment #2
alberto56 CreditAttribution: alberto56 commentedfrom what I can tell, It's a chart problem because it's logically valid to have zero as a max value.
The patch works for me, thanks. However I'll leave it at "needs review" because I'm not entirely sure how this function works, especially with negative ranges, ranges from negative to zero, and other case.
Comment #3
mstef CreditAttribution: mstef commentedI did:
Comment #4
Fleshgrinder CreditAttribution: Fleshgrinder commentedIt should be:
Because negative values will also produce errors.
Comment #5
mstef CreditAttribution: mstef commentedAttaching my patch
Comment #6
mstef CreditAttribution: mstef commentedSurprised to see 1.3 release not including this
Comment #7
ManyNancy CreditAttribution: ManyNancy commentedChanges to major as the error message is ugly.
Comment #8
mstef CreditAttribution: mstef commentedPatch for the new 1.3 release
Comment #9
aaron1234nz CreditAttribution: aaron1234nz commentedPatch in #8 applies (with a slight fuzz) and fixes the problem.
Comment #10
craigmc CreditAttribution: craigmc commentedYup. tested, works. plz include in module.
Comment #11
ximo CreditAttribution: ximo commentedHere's a hotfix patch for 7.x-1.0, in case anyone's in need of that. I did the same as Fleshgrinder in #4.
Comment #12
13rac1 CreditAttribution: 13rac1 commented@ximo: Git reports "fatal: git diff header lacks filename information when removing 1 leading pathname components (line 5)" for your patch. I manually applied the change.
This fix has been committed to 7.x-1.x-dev. May be changed again when #234127: Negative Data values? and #1213796: _chart_adjust_resolution calculation are resolved.
Comment #13
13rac1 CreditAttribution: 13rac1 commentedApplied to change in #11 to 6.x-1.x.
Comment #15
Juan David CreditAttribution: Juan David commentedThanks for the tip, it really works and make the warning go away.
sorry for my english.
Thanks again.
Comment #16
Pierre.Vriens CreditAttribution: Pierre.Vriens commented