From 1dc11867601194d5bdaa15ff25a58eba331830c1 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 26 Apr 2021 20:41:28 -0700 Subject: [PATCH] clang-tidy: simplify boolean expressions Found with readability-simplify-boolean-expr Signed-off-by: Rosen Penev --- samples/metacopy.cpp | 2 +- src/actions.cpp | 4 ++-- src/basicio.cpp | 2 +- src/crwimage.cpp | 3 +-- src/image.cpp | 2 +- src/jp2image.cpp | 5 ++--- src/jpgimage.cpp | 6 +++--- src/makernote_int.cpp | 35 ++++++++++------------------------- src/pngimage.cpp | 2 +- src/psdimage.cpp | 20 ++++++++++---------- src/tiffvisitor_int.cpp | 8 ++------ src/xmpsidecar.cpp | 3 +-- 12 files changed, 35 insertions(+), 57 deletions(-) diff --git a/samples/metacopy.cpp b/samples/metacopy.cpp index 39952273..fa00b0d7 100644 --- a/samples/metacopy.cpp +++ b/samples/metacopy.cpp @@ -147,7 +147,7 @@ int Params::getopt(int argc, char* const argv[]) { int rc = Util::Getopt::getopt(argc, argv, optstring_); // Further consistency checks - if (help_==false) { + if (!help_) { if (rc==0 && read_.empty() ) { std::cerr << progname() << ": Read and write files must be specified\n"; rc = 1; diff --git a/src/actions.cpp b/src/actions.cpp index 88c177c1..e075a3b2 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -917,7 +917,7 @@ namespace Action { path_ = path; int rc = 0; - bool bStdout = Params::instance().target_ & Params::ctStdInOut ? true : false; + bool bStdout = (Params::instance().target_ & Params::ctStdInOut) != 0; if (bStdout) { _setmode(_fileno(stdout), _O_BINARY); } @@ -1103,7 +1103,7 @@ namespace Action { int Insert::run(const std::string& path) try { // -i{tgt}- reading from stdin? - bool bStdin = (Params::instance().target_ & Params::ctStdInOut)?true:false; + bool bStdin = (Params::instance().target_ & Params::ctStdInOut) != 0; if (!Exiv2::fileExists(path, true)) { std::cerr << path diff --git a/src/basicio.cpp b/src/basicio.cpp index f6c0e336..b448480e 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -1697,7 +1697,7 @@ namespace Exiv2 { { close(); // reset the IO position bigBlock_ = NULL; - if (p_->isMalloced_ == false) { + if (!p_->isMalloced_) { long length = p_->getFileLength(); if (length < 0) { // unable to get the length of remote file, get the whole file content. std::string data; diff --git a/src/crwimage.cpp b/src/crwimage.cpp index db31505d..fdbfa8fb 100644 --- a/src/crwimage.cpp +++ b/src/crwimage.cpp @@ -204,8 +204,7 @@ namespace Exiv2 { || ('M' == tmpBuf[0] && 'M' == tmpBuf[1]))) { result = false; } - if ( true == result - && std::memcmp(tmpBuf + 6, CiffHeader::signature(), 8) != 0) { + if (result && std::memcmp(tmpBuf + 6, CiffHeader::signature(), 8) != 0) { result = false; } if (!advance || !result) iIo.seek(-14, BasicIo::cur); diff --git a/src/image.cpp b/src/image.cpp index be44773e..35738e5e 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -227,7 +227,7 @@ namespace Exiv2 { char c[4]; } e = { 0x01000000 }; - return e.c[0]?true:false; + return e.c[0] != 0; } bool Image::isLittleEndianPlatform() { return !isBigEndianPlatform(); } diff --git a/src/jp2image.cpp b/src/jp2image.cpp index 573a92f1..1d0ef2d4 100644 --- a/src/jp2image.cpp +++ b/src/jp2image.cpp @@ -180,7 +180,7 @@ namespace Exiv2 char c[4]; } e = { 0x01000000 }; - return e.c[0]?true:false; + return e.c[0] != 0; } static std::string toAscii(long n) @@ -874,8 +874,7 @@ static void boxes_check(size_t b,size_t m) } } - if (writeXmpFromPacket() == false) - { + if (!writeXmpFromPacket()) { if (XmpParser::encode(xmpPacket_, xmpData_) > 1) { #ifndef SUPPRESS_WARNINGS diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index c5510d0c..34970299 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -1059,9 +1059,9 @@ namespace Exiv2 { } if (exifData_.count() > 0) ++search; - if (writeXmpFromPacket() == false && xmpData_.count() > 0) + if (!writeXmpFromPacket() && xmpData_.count() > 0) ++search; - if (writeXmpFromPacket() == true && xmpPacket_.size() > 0) + if (writeXmpFromPacket() && xmpPacket_.size() > 0) ++search; if (foundCompletePsData || iptcData_.count() > 0) ++search; @@ -1125,7 +1125,7 @@ namespace Exiv2 { --search; } } - if (writeXmpFromPacket() == false) { + if (!writeXmpFromPacket()) { if (XmpParser::encode(xmpPacket_, xmpData_, XmpParser::useCompactFormat | XmpParser::omitAllFormatting) > 1) { #ifndef SUPPRESS_WARNINGS diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index 0dba71f5..faec4a36 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -258,11 +258,8 @@ namespace Exiv2 { if (!pData || size < sizeOfSignature()) return false; header_.alloc(sizeOfSignature()); std::memcpy(header_.pData_, pData, header_.size_); - if ( static_cast(header_.size_) < sizeOfSignature() - || 0 != memcmp(header_.pData_, signature_, 6)) { - return false; - } - return true; + return !(static_cast(header_.size_) < sizeOfSignature() || + 0 != memcmp(header_.pData_, signature_, 6)); } // OlympusMnHeader::read uint32_t OlympusMnHeader::write(IoWrapper& ioWrapper, @@ -310,11 +307,8 @@ namespace Exiv2 { if (!pData || size < sizeOfSignature()) return false; header_.alloc(sizeOfSignature()); std::memcpy(header_.pData_, pData, header_.size_); - if ( static_cast(header_.size_) < sizeOfSignature() - || 0 != memcmp(header_.pData_, signature_, 10)) { - return false; - } - return true; + return !(static_cast(header_.size_) < sizeOfSignature() || + 0 != memcmp(header_.pData_, signature_, 10)); } // Olympus2MnHeader::read uint32_t Olympus2MnHeader::write(IoWrapper& ioWrapper, @@ -371,11 +365,8 @@ namespace Exiv2 { // Read offset to the IFD relative to the start of the makernote // from the header. Note that we ignore the byteOrder argument start_ = getULong(header_.pData_ + 8, byteOrder_); - if ( static_cast(header_.size_) < sizeOfSignature() - || 0 != memcmp(header_.pData_, signature_, 8)) { - return false; - } - return true; + return !(static_cast(header_.size_) < sizeOfSignature() || + 0 != memcmp(header_.pData_, signature_, 8)); } // FujiMnHeader::read uint32_t FujiMnHeader::write(IoWrapper& ioWrapper, @@ -587,11 +578,8 @@ namespace Exiv2 { if (!pData || size < sizeOfSignature()) return false; header_.alloc(sizeOfSignature()); std::memcpy(header_.pData_, pData, header_.size_); - if ( static_cast(header_.size_) < sizeOfSignature() - || 0 != memcmp(header_.pData_, signature_, 7)) { - return false; - } - return true; + return !(static_cast(header_.size_) < sizeOfSignature() || + 0 != memcmp(header_.pData_, signature_, 7)); } // PentaxDngMnHeader::read uint32_t PentaxDngMnHeader::write(IoWrapper& ioWrapper, @@ -634,11 +622,8 @@ namespace Exiv2 { if (!pData || size < sizeOfSignature()) return false; header_.alloc(sizeOfSignature()); std::memcpy(header_.pData_, pData, header_.size_); - if ( static_cast(header_.size_) < sizeOfSignature() - || 0 != memcmp(header_.pData_, signature_, 3)) { - return false; - } - return true; + return !(static_cast(header_.size_) < sizeOfSignature() || + 0 != memcmp(header_.pData_, signature_, 3)); } // PentaxMnHeader::read uint32_t PentaxMnHeader::write(IoWrapper& ioWrapper, diff --git a/src/pngimage.cpp b/src/pngimage.cpp index b2fdbcbd..054026db 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -678,7 +678,7 @@ namespace Exiv2 { } } - if (writeXmpFromPacket() == false) { + if (!writeXmpFromPacket()) { if (XmpParser::encode(xmpPacket_, xmpData_) > 1) { #ifndef SUPPRESS_WARNINGS EXV_ERROR << "Failed to encode XMP metadata.\n"; diff --git a/src/psdimage.cpp b/src/psdimage.cpp index 47ee993b..5f48cca2 100644 --- a/src/psdimage.cpp +++ b/src/psdimage.cpp @@ -461,22 +461,22 @@ namespace Exiv2 { uint32_t curOffset = io_->tell(); // Write IPTC_NAA resource block - if ((resourceId == kPhotoshopResourceID_IPTC_NAA || - resourceId > kPhotoshopResourceID_IPTC_NAA) && iptcDone == false) { + if ((resourceId == kPhotoshopResourceID_IPTC_NAA || resourceId > kPhotoshopResourceID_IPTC_NAA) && + !iptcDone) { newResLength += writeIptcData(iptcData_, outIo); iptcDone = true; } // Write ExifInfo resource block - else if ((resourceId == kPhotoshopResourceID_ExifInfo || - resourceId > kPhotoshopResourceID_ExifInfo) && exifDone == false) { + else if ((resourceId == kPhotoshopResourceID_ExifInfo || resourceId > kPhotoshopResourceID_ExifInfo) && + !exifDone) { newResLength += writeExifData(exifData_, outIo); exifDone = true; } // Write XMPpacket resource block - else if ((resourceId == kPhotoshopResourceID_XMPPacket || - resourceId > kPhotoshopResourceID_XMPPacket) && xmpDone == false) { + else if ((resourceId == kPhotoshopResourceID_XMPPacket || resourceId > kPhotoshopResourceID_XMPPacket) && + !xmpDone) { newResLength += writeXmpData(xmpData_, outIo); xmpDone = true; } @@ -525,19 +525,19 @@ namespace Exiv2 { } // Append IPTC_NAA resource block, if not yet written - if (iptcDone == false) { + if (!iptcDone) { newResLength += writeIptcData(iptcData_, outIo); iptcDone = true; } // Append ExifInfo resource block, if not yet written - if (exifDone == false) { + if (!exifDone) { newResLength += writeExifData(exifData_, outIo); exifDone = true; } // Append XmpPacket resource block, if not yet written - if (xmpDone == false) { + if (!xmpDone) { newResLength += writeXmpData(xmpData_, outIo); xmpDone = true; } @@ -646,7 +646,7 @@ namespace Exiv2 { std::cerr << "writeXmpFromPacket(): " << writeXmpFromPacket() << "\n"; #endif // writeXmpFromPacket(true); - if (writeXmpFromPacket() == false) { + if (!writeXmpFromPacket()) { if (XmpParser::encode(xmpPacket, xmpData) > 1) { #ifndef SUPPRESS_WARNINGS EXV_ERROR << "Failed to encode XMP metadata.\n"; diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index 3f155e23..6ad9cb5c 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -705,8 +705,7 @@ namespace Exiv2 { bool TiffEncoder::dirty() const { - if (dirty_ || exifData_.count() > 0) return true; - return false; + return dirty_ || exifData_.count() > 0; } void TiffEncoder::visitEntry(TiffEntry* object) @@ -869,10 +868,7 @@ namespace Exiv2 { bool TiffEncoder::isImageTag(uint16_t tag, IfdId group) const { - if (!isNewImage_ && pHeader_->isImageTag(tag, group, pPrimaryGroups_)) { - return true; - } - return false; + return !isNewImage_ && pHeader_->isImageTag(tag, group, pPrimaryGroups_); } void TiffEncoder::encodeTiffComponent( diff --git a/src/xmpsidecar.cpp b/src/xmpsidecar.cpp index ebc1872c..fe99b4b3 100644 --- a/src/xmpsidecar.cpp +++ b/src/xmpsidecar.cpp @@ -131,8 +131,7 @@ namespace Exiv2 { } IoCloser closer(*io_); - - if (writeXmpFromPacket() == false) { + if (!writeXmpFromPacket()) { // #589 copy XMP tags Exiv2::XmpData copy ; for (auto&& it : xmpData_) {