From ad3e17476e5288bea37a24e08db72386e920a04d Mon Sep 17 00:00:00 2001 From: Dmitry Karasik Date: Tue, 3 Oct 2023 12:13:54 +0200 Subject: [PATCH] protect against div/0 --- Prima/Drawable/Gradient.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Prima/Drawable/Gradient.pm b/Prima/Drawable/Gradient.pm index af89abc75..1262c1bef 100644 --- a/Prima/Drawable/Gradient.pm +++ b/Prima/Drawable/Gradient.pm @@ -162,9 +162,14 @@ sub calculate_single $d1 += ($_ - $l) * ($_ - $l); $d2 += ($r - $l) * ($r - $l); } - $fp = int(sqrt($d1) / sqrt($d2) * 64 ); - $c1 = ( $l[0] << 16 ) | ( $l[1] << 8 ) | $l[2]; - $c2 = ( $r[0] << 16 ) | ( $r[1] << 8 ) | $r[2]; + if ( $d2 > 0 ) { + $fp = int(sqrt($d1 / $d2) * 64 ); + $c1 = ( $l[0] << 16 ) | ( $l[1] << 8 ) | $l[2]; + $c2 = ( $r[0] << 16 ) | ( $r[1] << 8 ) | $r[2]; + } else { + $c1 = $c2 = ( $l[0] << 16 ) | ( $l[1] << 8 ) | $l[2]; + $fp = 0; + } } my $new_stripe = 1; if ( @ret ) {