Skip to content

Commit

Permalink
cland-tidy: simplify booleans
Browse files Browse the repository at this point in the history
Found with readability-simplify-boolean-expr

Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
neheb committed Sep 25, 2022
1 parent 84f566b commit b0bbe6a
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/exiv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ int Params::getopt(int argc, char* const Argv[]) {
// We'll set them again, after reading the file
Exiv2::XmpProperties::unregisterNs();
}
if (!directory_.empty() && !(action_ == Action::insert || action_ == Action::extract)) {
if (!directory_.empty() && action_ != Action::insert && action_ != Action::extract) {
std::cerr << progname() << ": " << _("-l option can only be used with extract or insert actions\n");
rc = 1;
}
Expand Down Expand Up @@ -1221,7 +1221,7 @@ int parsePreviewNumbers(Params::PreviewNumbers& previewNumbers, const std::strin
}
i = k;
}
if (!(k < optArg.size() && optArg[i] == ','))
if (k >= optArg.size() || optArg[i] != ',')
break;
}
auto ret = static_cast<int>(k - j);
Expand Down
2 changes: 1 addition & 1 deletion src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ void Converter::cnvXmpGPSCoord(const char* from, const char* to) {
min = static_cast<double>(static_cast<int>(min));
}

if (in.bad() || !(ref == 'N' || ref == 'S' || ref == 'E' || ref == 'W') || sep1 != ',' || !in.eof()) {
if (in.bad() || (ref != 'N' && ref != 'S' && ref != 'E' && ref != 'W') || sep1 != ',' || !in.eof()) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/crwimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bool isCrwType(BasicIo& iIo, bool advance) {
if (iIo.error() || iIo.eof()) {
return false;
}
if (!(('I' == tmpBuf[0] && 'I' == tmpBuf[1]) || ('M' == tmpBuf[0] && 'M' == tmpBuf[1]))) {
if (('I' != tmpBuf[0] || 'I' != tmpBuf[1]) && ('M' != tmpBuf[0] || 'M' != tmpBuf[1])) {
result = false;
}
if (result && std::memcmp(tmpBuf + 6, Internal::CiffHeader::signature(), 8) != 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/epsimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
EXV_DEBUG << "readWriteEpsMetadata: DOS EPS checksum is not FFFF\n";
#endif
}
if (!((posWmf == 0 && sizeWmf == 0) || (posTiff == 0 && sizeTiff == 0))) {
if ((posWmf != 0 || sizeWmf != 0) && (posTiff != 0 || sizeTiff != 0)) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "DOS EPS file has both WMF and TIFF section. Only one of those is allowed.\n";
#endif
Expand Down Expand Up @@ -472,8 +472,8 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
significantLine = true;
#endif
// implicit comments
if (line == "%%EOF" || line == "%begin_xml_code" ||
!(line.size() >= 2 && line.front() == '%' && '\x21' <= line[1] && line[1] <= '\x7e')) {
if (line == "%%EOF" || line == "%begin_xml_code" || line.size() < 2 || line.front() != '%' || '\x21' > line[1] ||
line[1] > '\x7e') {
if (posEndComments == posEndEps) {
posEndComments = startPos;
#ifdef DEBUG
Expand Down
12 changes: 6 additions & 6 deletions src/makernote_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ bool OlympusMnHeader::read(const byte* pData, size_t size, ByteOrder /*byteOrder
return false;
header_.alloc(sizeOfSignature());
std::copy_n(pData, header_.size(), header_.data());
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 6));
return header_.size() >= sizeOfSignature() && 0 == header_.cmpBytes(0, signature_, 6);
}

size_t OlympusMnHeader::write(IoWrapper& ioWrapper, ByteOrder /*byteOrder*/) const {
Expand Down Expand Up @@ -222,7 +222,7 @@ bool Olympus2MnHeader::read(const byte* pData, size_t size, ByteOrder /*byteOrde
return false;
header_.alloc(sizeOfSignature());
std::copy_n(pData, header_.size(), header_.data());
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 10));
return header_.size() >= sizeOfSignature() && 0 == header_.cmpBytes(0, signature_, 10);
}

size_t Olympus2MnHeader::write(IoWrapper& ioWrapper, ByteOrder /*byteOrder*/) const {
Expand Down Expand Up @@ -258,7 +258,7 @@ bool OMSystemMnHeader::read(const byte* pData, size_t size, ByteOrder /*byteOrde
return false;
header_.alloc(sizeOfSignature());
std::copy_n(pData, header_.size(), header_.data());
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, sizeOfSignature() - 2));
return header_.size() >= sizeOfSignature() && 0 == header_.cmpBytes(0, signature_, sizeOfSignature() - 2);
}

size_t OMSystemMnHeader::write(IoWrapper& ioWrapper, ByteOrder /*byteOrder*/) const {
Expand Down Expand Up @@ -301,7 +301,7 @@ bool FujiMnHeader::read(const byte* pData, size_t size, ByteOrder /*byteOrder*/)
// Read offset to the IFD relative to the start of the makernote
// from the header. Note that we ignore the byteOrder argument
start_ = header_.read_uint32(8, byteOrder_);
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 8));
return header_.size() >= sizeOfSignature() && 0 == header_.cmpBytes(0, signature_, 8);
}

size_t FujiMnHeader::write(IoWrapper& ioWrapper, ByteOrder /*byteOrder*/) const {
Expand Down Expand Up @@ -460,7 +460,7 @@ bool PentaxDngMnHeader::read(const byte* pData, size_t size, ByteOrder /*byteOrd
return false;
header_.alloc(sizeOfSignature());
std::copy_n(pData, header_.size(), header_.data());
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 7));
return header_.size() >= sizeOfSignature() && 0 == header_.cmpBytes(0, signature_, 7);
}

size_t PentaxDngMnHeader::write(IoWrapper& ioWrapper, ByteOrder /*byteOrder*/) const {
Expand Down Expand Up @@ -491,7 +491,7 @@ bool PentaxMnHeader::read(const byte* pData, size_t size, ByteOrder /*byteOrder*
return false;
header_.alloc(sizeOfSignature());
std::copy_n(pData, header_.size(), header_.data());
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 3));
return header_.size() >= sizeOfSignature() && 0 == header_.cmpBytes(0, signature_, 3);
}

size_t PentaxMnHeader::write(IoWrapper& ioWrapper, ByteOrder /*byteOrder*/) const {
Expand Down
2 changes: 1 addition & 1 deletion src/olympusmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ const TagInfo* OlympusMakerNote::tagListRi() {

// Gradation
std::ostream& OlympusMakerNote::print0x050f(std::ostream& os, const Value& value, const ExifData*) {
if (!(value.count() == 3 || value.count() == 4) || value.typeId() != signedShort) {
if ((value.count() != 3 && value.count() != 4) || value.typeId() != signedShort) {
return os << value;
}

Expand Down
2 changes: 1 addition & 1 deletion src/preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ PreviewId Loader::getNumLoaders() {
}

LoaderNative::LoaderNative(PreviewId id, const Image& image, int parIdx) : Loader(id, image) {
if (!(0 <= parIdx && static_cast<size_t>(parIdx) < image.nativePreviews().size()))
if (0 > parIdx || static_cast<size_t>(parIdx) >= image.nativePreviews().size())
return;
nativePreview_ = image.nativePreviews()[parIdx];
width_ = nativePreview_.width_;
Expand Down
2 changes: 1 addition & 1 deletion src/tags_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3034,7 +3034,7 @@ std::ostream& printXmpVersion(std::ostream& os, const Value& value, const ExifDa
}

std::ostream& printXmpDate(std::ostream& os, const Value& value, const ExifData*) {
if (!(value.size() == 19 || value.size() == 20) || value.typeId() != xmpText) {
if ((value.size() != 19 && value.size() != 20) || value.typeId() != xmpText) {
return os << value;
}

Expand Down

0 comments on commit b0bbe6a

Please sign in to comment.