From 6d1fa2ecea1bd2c673c1617cec9917faaf606a1a Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 5 Mar 2022 01:49:27 -0800 Subject: [PATCH] clang-tidy: use empty() instead of size() Signed-off-by: Rosen Penev --- app/actions.cpp | 4 ++-- app/exiv2.cpp | 2 +- src/crwimage_int.cpp | 10 ++++------ src/jp2image.cpp | 3 +-- src/jpgimage.cpp | 2 +- src/pngchunk_int.cpp | 4 ++-- src/pngimage.cpp | 7 +++---- src/psdimage.cpp | 4 ++-- src/tiffcomposite_int.cpp | 2 +- src/tiffvisitor_int.cpp | 11 ++++++----- 10 files changed, 23 insertions(+), 26 deletions(-) diff --git a/app/actions.cpp b/app/actions.cpp index a53fd35e..46130052 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -902,7 +902,7 @@ namespace Action { if (dontOverwrite(thumbPath)) return 0; if (Params::instance().verbose_) { Exiv2::DataBuf buf = exifThumb.copy(); - if (buf.size() != 0) { + if (!buf.empty()) { std::cout << _("Writing thumbnail") << " (" << exifThumb.mimeType() << ", " << buf.size() << " " << _("Bytes") << ") " << _("to file") << " " << thumbPath << std::endl; @@ -1150,7 +1150,7 @@ namespace Action { image->readMetadata(); // clear existing profile, assign the blob and rewrite image image->clearIccProfile(); - if ( iccProfileBlob.size() ) { + if (!iccProfileBlob.empty()) { image->setIccProfile(std::move(iccProfileBlob)); } image->writeMetadata(); diff --git a/app/exiv2.cpp b/app/exiv2.cpp index 48d19687..64171e9e 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -1010,7 +1010,7 @@ void Params::getStdin(Exiv2::DataBuf& buf) } // copy stdinBuf to buf - if ( stdinBuf.size() ) { + if (!stdinBuf.empty()) { buf.alloc(stdinBuf.size()); buf.copyBytes(0,stdinBuf.c_data(),buf.size()); } diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 82e414c7..ab6c4753 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -1063,12 +1063,11 @@ namespace Exiv2::Internal { // Try the undecoded tag encodeBasic(image, pCrwMapping, pHead); } - if (buf.size() > 0) { + if (!buf.empty()) { // Write the number of shorts to the beginning of buf buf.write_uint16(0, static_cast(buf.size()), pHead->byteOrder()); pHead->add(pCrwMapping->crwTagId_, pCrwMapping->crwDir_, std::move(buf)); - } - else { + } else { pHead->remove(pCrwMapping->crwTagId_, pCrwMapping->crwDir_); } } // CrwMap::encodeArray @@ -1154,10 +1153,9 @@ namespace Exiv2::Internal { ExifThumbC exifThumb(image.exifData()); DataBuf buf = exifThumb.copy(); - if (buf.size() != 0) { + if (!buf.empty()) { pHead->add(pCrwMapping->crwTagId_, pCrwMapping->crwDir_, std::move(buf)); - } - else { + } else { pHead->remove(pCrwMapping->crwTagId_, pCrwMapping->crwDir_); } } // CrwMap::encode0x2008 diff --git a/src/jp2image.cpp b/src/jp2image.cpp index 8ff222cd..a9eee89c 100644 --- a/src/jp2image.cpp +++ b/src/jp2image.cpp @@ -845,8 +845,7 @@ static void boxes_check(size_t b,size_t m) // Update Iptc data to a new UUID box DataBuf rawIptc = IptcParser::encode(iptcData_); - if (rawIptc.size() > 0) - { + if (!rawIptc.empty()) { DataBuf boxData(8 + 16 + rawIptc.size()); ul2Data(boxDataSize, static_cast(boxData.size()), Exiv2::bigEndian); ul2Data(boxUUIDtype, kJp2BoxTypeUuid, Exiv2::bigEndian); diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index 8b08ce3b..5c1b6baf 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -419,7 +419,7 @@ namespace Exiv2 { } DataBuf profile(Safe::add(iccProfile_.size(), icc_size)); - if ( iccProfile_.size() ) { + if (!iccProfile_.empty()) { profile.copyBytes(0, iccProfile_.c_data(), iccProfile_.size()); } profile.copyBytes(iccProfile_.size(), buf.c_data(2+14), icc_size); diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp index 64b996e0..53105c22 100644 --- a/src/pngchunk_int.cpp +++ b/src/pngchunk_int.cpp @@ -240,7 +240,7 @@ namespace Exiv2::Internal { if (keySize >= 21 && memcmp("Raw profile type iptc", key, 21) == 0 && pImage->iptcData().empty()) { DataBuf psData = readRawProfile(arr, false); - if (psData.size() > 0) { + if (!psData.empty()) { Blob iptcBlob; const byte* record = nullptr; uint32_t sizeIptc = 0; @@ -303,7 +303,7 @@ namespace Exiv2::Internal { // We look if an Adobe XMP string exist. if (keySize >= 17 && memcmp("XML:com.adobe.xmp", key, 17) == 0 && pImage->xmpData().empty()) { - if (arr.size() > 0) { + if (!arr.empty()) { std::string& xmpPacket = pImage->xmpPacket(); xmpPacket.assign(arr.c_str(), arr.size()); std::string::size_type idx = xmpPacket.find_first_of('<'); diff --git a/src/pngimage.cpp b/src/pngimage.cpp index 952a3d5f..d2f2f36c 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -342,7 +342,7 @@ namespace Exiv2 { #if EXIV2_DEBUG_MESSAGES std::cerr << Exiv2::Internal::binaryToString(makeSlice(parsedBuf.c_data(), parsedBuf.size()>50?50:parsedBuf.size(),0)) << std::endl; #endif - if ( parsedBuf.size() ) { + if (!parsedBuf.empty()) { if ( bExif ) { // create memio object with the data, then print the structure MemIo p(parsedBuf.c_data(6), parsedBuf.size()-6); @@ -354,7 +354,7 @@ namespace Exiv2 { } } - if ( bSoft && dataBuf.size() > 0) { + if (bSoft && !dataBuf.empty()) { DataBuf s(dataBuf.size()+1); // allocate buffer with an extra byte s.copyBytes(0,dataBuf.c_data(),dataBuf.size());// copy in the dataBuf s.write_uint8(dataBuf.size(), 0); // nul terminate it @@ -621,8 +621,7 @@ namespace Exiv2 { { // Update IPTC data to a new PNG chunk DataBuf newPsData = Photoshop::setIptcIrb(nullptr, 0, iptcData_); - if (newPsData.size() > 0) - { + if (!newPsData.empty()) { std::string rawIptc(newPsData.c_str(), newPsData.size()); std::string chunk = PngChunk::makeMetadataChunk(rawIptc, mdIptc); if (outIo.write(reinterpret_cast(chunk.data()), chunk.size()) != chunk.size()) { diff --git a/src/psdimage.cpp b/src/psdimage.cpp index 118f352b..de491f95 100644 --- a/src/psdimage.cpp +++ b/src/psdimage.cpp @@ -250,7 +250,7 @@ namespace Exiv2 { throw Error(kerFailedToReadImageData); ByteOrder bo = ExifParser::decode(exifData_, rawExif.c_data(), rawExif.size()); setByteOrder(bo); - if (rawExif.size() > 0 && byteOrder() == invalidByteOrder) { + if (!rawExif.empty() && byteOrder() == invalidByteOrder) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Failed to decode Exif metadata.\n"; #endif @@ -579,7 +579,7 @@ namespace Exiv2 { if (iptcData.count() > 0) { DataBuf rawIptc = IptcParser::encode(iptcData); - if (rawIptc.size() > 0) { + if (!rawIptc.empty()) { #ifdef EXIV2_DEBUG_MESSAGES std::cerr << std::hex << "write: resourceId: " << kPhotoshopResourceID_IPTC_NAA << "\n"; std::cerr << std::dec << "Writing IPTC_NAA: size: " << rawIptc.size() << "\n"; diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index d3c07f73..4fb378e6 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -1391,7 +1391,7 @@ namespace Exiv2::Internal { cryptFct = sonyTagEncipher; } DataBuf buf = cryptFct(tag(), mio.mmap(), static_cast(mio.size()), pRoot_); - if ( buf.size()) { + if (!buf.empty()) { mio.seek(0,Exiv2::FileIo::beg); mio.write(buf.c_data(), buf.size()); } diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index f66bd4f0..b6e22fb4 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -599,7 +599,7 @@ namespace Exiv2::Internal { if (pos != exifData_.end()) { irbKey.setIdx(pos->idx()); } - if (rawIptc.size() != 0 && (del || pos == exifData_.end())) { + if (!rawIptc.empty() && (del || pos == exifData_.end())) { auto value = Value::create(unsignedLong); DataBuf buf; if (rawIptc.size() % 4 != 0) { @@ -622,7 +622,7 @@ namespace Exiv2::Internal { pos->value().copy(irbBuf.data(), invalidByteOrder); irbBuf = Photoshop::setIptcIrb(irbBuf.c_data(), irbBuf.size(), iptcData_); exifData_.erase(pos); - if (irbBuf.size() != 0) { + if (!irbBuf.empty()) { auto value = Value::create(unsignedByte); value->read(irbBuf.data(), static_cast(irbBuf.size()), invalidByteOrder); Exifdatum iptcDatum(irbKey, value.get()); @@ -815,7 +815,7 @@ namespace Exiv2::Internal { if (cryptFct != nullptr) { const byte* pData = object->pData(); DataBuf buf = cryptFct(object->tag(), pData, size, pRoot_); - if (buf.size() > 0) { + if (!buf.empty()) { pData = buf.c_data(); size = static_cast(buf.size()); } @@ -930,7 +930,7 @@ namespace Exiv2::Internal { std::cerr << "Writing data area for " << key << "\n"; #endif DataBuf buf = object->pValue()->dataArea(); - if ( buf.size() > 0 ) { + if (!buf.empty()) { memcpy(object->pDataArea_, buf.c_data(), buf.size()); if (object->sizeDataArea_ > static_cast(buf.size())) { memset(object->pDataArea_ + buf.size(), @@ -1639,7 +1639,8 @@ namespace Exiv2::Internal { std::shared_ptr buf = std::make_shared( cryptFct(object->tag(), pData, size, pRoot_) ); - if (buf->size() > 0) object->setData(buf); + if (!buf->empty()) + object->setData(buf); } const ArrayDef* defs = object->def();