Skip to content

Commit d1b5f9e

Browse files
author
Cristy
committed
check for negative sqrt()
1 parent 7e4b327 commit d1b5f9e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

magick/compare.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,24 +1633,26 @@ static MagickBooleanType GetRootMeanSquaredDistortion(const Image *image,
16331633
const Image *reconstruct_image,const ChannelType channel,double *distortion,
16341634
ExceptionInfo *exception)
16351635
{
1636+
#define RMSESquareRoot(x) sqrt((x) < 0.0 ? 0.0 : (x))
1637+
16361638
MagickBooleanType
16371639
status;
16381640

16391641
status=GetMeanSquaredDistortion(image,reconstruct_image,channel,distortion,
16401642
exception);
16411643
if ((channel & RedChannel) != 0)
1642-
distortion[RedChannel]=sqrt(distortion[RedChannel]);
1644+
distortion[RedChannel]=RMSESquareRoot(distortion[RedChannel]);
16431645
if ((channel & GreenChannel) != 0)
1644-
distortion[GreenChannel]=sqrt(distortion[GreenChannel]);
1646+
distortion[GreenChannel]=RMSESquareRoot(distortion[GreenChannel]);
16451647
if ((channel & BlueChannel) != 0)
1646-
distortion[BlueChannel]=sqrt(distortion[BlueChannel]);
1648+
distortion[BlueChannel]=RMSESquareRoot(distortion[BlueChannel]);
16471649
if (((channel & OpacityChannel) != 0) &&
16481650
(image->matte != MagickFalse))
1649-
distortion[OpacityChannel]=sqrt(distortion[OpacityChannel]);
1651+
distortion[OpacityChannel]=RMSESquareRoot(distortion[OpacityChannel]);
16501652
if (((channel & IndexChannel) != 0) &&
16511653
(image->colorspace == CMYKColorspace))
1652-
distortion[BlackChannel]=sqrt(distortion[BlackChannel]);
1653-
distortion[CompositeChannels]=sqrt(distortion[CompositeChannels]);
1654+
distortion[BlackChannel]=RMSESquareRoot(distortion[BlackChannel]);
1655+
distortion[CompositeChannels]=RMSESquareRoot(distortion[CompositeChannels]);
16541656
return(status);
16551657
}
16561658

0 commit comments

Comments
 (0)