simplify boolean expression, found by PVS analyzer (#1318)
authorIlya Shipitsin <chipitsine@gmail.com>
Sat, 22 Sep 2018 22:57:34 +0000 (03:57 +0500)
committerImageMagick <urban-warrior@users.noreply.github.com>
Sat, 22 Sep 2018 22:57:34 +0000 (18:57 -0400)
Magick++/lib/Color.cpp 303 warn V728 An excessive check can be simplified. The '(A && B) || (!A && !B)' expression is equivalent to the 'bool(A) == bool(B)' expression.
Magick++/lib/Image.cpp 314 warn V728 An excessive check can be simplified. The '(A && !B) || (!A && B)' expression is equivalent to the 'bool(A) != bool(B)' expression.

Magick++/lib/Color.cpp
Magick++/lib/Image.cpp

index f8de206ee4f81d6e3207a4ea1b528ddcffa2c472..4f1611bded1666bbdc2041f7b629b08266bb9c8c 100644 (file)
@@ -300,7 +300,7 @@ Magick::Color::PixelType Magick::Color::pixelType() const
 
 void Magick::Color::isValid(bool valid_)
 {
-  if ((valid_ && isValid()) || (!valid_ && !isValid()))
+  if (bool(valid_) == bool(isValid()))
     return;
 
   if (!_pixelOwn)
index ec1688490409d30e14313bf1abe94bc37fb289a1..a6dfcf0f33969174c88169a67669fc62eef4b8a2 100644 (file)
@@ -311,8 +311,7 @@ void Magick::Image::alpha(const bool alphaFlag_)
   // the image already has a matte channel but a matte channel is not
   // desired, then set the matte channel to opaque.
   GetPPException;
-  if ((alphaFlag_ && !constImage()->alpha_trait) ||
-      (constImage()->alpha_trait && !alphaFlag_))
+  if (bool(alphaFlag_) != bool(constImage()->alpha_trait))
     SetImageAlpha(image(),OpaqueAlpha,exceptionInfo);
   ThrowImageException;