clang-tidy: use empty() instead of size()

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 3 years ago
parent 5833101b9b
commit 6d1fa2ecea

@ -902,7 +902,7 @@ namespace Action {
if (dontOverwrite(thumbPath)) return 0; if (dontOverwrite(thumbPath)) return 0;
if (Params::instance().verbose_) { if (Params::instance().verbose_) {
Exiv2::DataBuf buf = exifThumb.copy(); Exiv2::DataBuf buf = exifThumb.copy();
if (buf.size() != 0) { if (!buf.empty()) {
std::cout << _("Writing thumbnail") << " (" << exifThumb.mimeType() << ", " std::cout << _("Writing thumbnail") << " (" << exifThumb.mimeType() << ", "
<< buf.size() << " " << _("Bytes") << ") " << _("to file") << " " << buf.size() << " " << _("Bytes") << ") " << _("to file") << " "
<< thumbPath << std::endl; << thumbPath << std::endl;
@ -1150,7 +1150,7 @@ namespace Action {
image->readMetadata(); image->readMetadata();
// clear existing profile, assign the blob and rewrite image // clear existing profile, assign the blob and rewrite image
image->clearIccProfile(); image->clearIccProfile();
if ( iccProfileBlob.size() ) { if (!iccProfileBlob.empty()) {
image->setIccProfile(std::move(iccProfileBlob)); image->setIccProfile(std::move(iccProfileBlob));
} }
image->writeMetadata(); image->writeMetadata();

@ -1010,7 +1010,7 @@ void Params::getStdin(Exiv2::DataBuf& buf)
} }
// copy stdinBuf to buf // copy stdinBuf to buf
if ( stdinBuf.size() ) { if (!stdinBuf.empty()) {
buf.alloc(stdinBuf.size()); buf.alloc(stdinBuf.size());
buf.copyBytes(0,stdinBuf.c_data(),buf.size()); buf.copyBytes(0,stdinBuf.c_data(),buf.size());
} }

@ -1063,12 +1063,11 @@ namespace Exiv2::Internal {
// Try the undecoded tag // Try the undecoded tag
encodeBasic(image, pCrwMapping, pHead); encodeBasic(image, pCrwMapping, pHead);
} }
if (buf.size() > 0) { if (!buf.empty()) {
// Write the number of shorts to the beginning of buf // Write the number of shorts to the beginning of buf
buf.write_uint16(0, static_cast<uint16_t>(buf.size()), pHead->byteOrder()); buf.write_uint16(0, static_cast<uint16_t>(buf.size()), pHead->byteOrder());
pHead->add(pCrwMapping->crwTagId_, pCrwMapping->crwDir_, std::move(buf)); pHead->add(pCrwMapping->crwTagId_, pCrwMapping->crwDir_, std::move(buf));
} } else {
else {
pHead->remove(pCrwMapping->crwTagId_, pCrwMapping->crwDir_); pHead->remove(pCrwMapping->crwTagId_, pCrwMapping->crwDir_);
} }
} // CrwMap::encodeArray } // CrwMap::encodeArray
@ -1154,10 +1153,9 @@ namespace Exiv2::Internal {
ExifThumbC exifThumb(image.exifData()); ExifThumbC exifThumb(image.exifData());
DataBuf buf = exifThumb.copy(); DataBuf buf = exifThumb.copy();
if (buf.size() != 0) { if (!buf.empty()) {
pHead->add(pCrwMapping->crwTagId_, pCrwMapping->crwDir_, std::move(buf)); pHead->add(pCrwMapping->crwTagId_, pCrwMapping->crwDir_, std::move(buf));
} } else {
else {
pHead->remove(pCrwMapping->crwTagId_, pCrwMapping->crwDir_); pHead->remove(pCrwMapping->crwTagId_, pCrwMapping->crwDir_);
} }
} // CrwMap::encode0x2008 } // CrwMap::encode0x2008

@ -845,8 +845,7 @@ static void boxes_check(size_t b,size_t m)
// Update Iptc data to a new UUID box // Update Iptc data to a new UUID box
DataBuf rawIptc = IptcParser::encode(iptcData_); DataBuf rawIptc = IptcParser::encode(iptcData_);
if (rawIptc.size() > 0) if (!rawIptc.empty()) {
{
DataBuf boxData(8 + 16 + rawIptc.size()); DataBuf boxData(8 + 16 + rawIptc.size());
ul2Data(boxDataSize, static_cast<uint32_t>(boxData.size()), Exiv2::bigEndian); ul2Data(boxDataSize, static_cast<uint32_t>(boxData.size()), Exiv2::bigEndian);
ul2Data(boxUUIDtype, kJp2BoxTypeUuid, Exiv2::bigEndian); ul2Data(boxUUIDtype, kJp2BoxTypeUuid, Exiv2::bigEndian);

@ -419,7 +419,7 @@ namespace Exiv2 {
} }
DataBuf profile(Safe::add(iccProfile_.size(), icc_size)); DataBuf profile(Safe::add(iccProfile_.size(), icc_size));
if ( iccProfile_.size() ) { if (!iccProfile_.empty()) {
profile.copyBytes(0, iccProfile_.c_data(), iccProfile_.size()); profile.copyBytes(0, iccProfile_.c_data(), iccProfile_.size());
} }
profile.copyBytes(iccProfile_.size(), buf.c_data(2+14), icc_size); profile.copyBytes(iccProfile_.size(), buf.c_data(2+14), icc_size);

@ -240,7 +240,7 @@ namespace Exiv2::Internal {
if (keySize >= 21 && memcmp("Raw profile type iptc", key, 21) == 0 && pImage->iptcData().empty()) { if (keySize >= 21 && memcmp("Raw profile type iptc", key, 21) == 0 && pImage->iptcData().empty()) {
DataBuf psData = readRawProfile(arr, false); DataBuf psData = readRawProfile(arr, false);
if (psData.size() > 0) { if (!psData.empty()) {
Blob iptcBlob; Blob iptcBlob;
const byte* record = nullptr; const byte* record = nullptr;
uint32_t sizeIptc = 0; uint32_t sizeIptc = 0;
@ -303,7 +303,7 @@ namespace Exiv2::Internal {
// We look if an Adobe XMP string exist. // We look if an Adobe XMP string exist.
if (keySize >= 17 && memcmp("XML:com.adobe.xmp", key, 17) == 0 && pImage->xmpData().empty()) { 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(); std::string& xmpPacket = pImage->xmpPacket();
xmpPacket.assign(arr.c_str(), arr.size()); xmpPacket.assign(arr.c_str(), arr.size());
std::string::size_type idx = xmpPacket.find_first_of('<'); std::string::size_type idx = xmpPacket.find_first_of('<');

@ -342,7 +342,7 @@ namespace Exiv2 {
#if EXIV2_DEBUG_MESSAGES #if EXIV2_DEBUG_MESSAGES
std::cerr << Exiv2::Internal::binaryToString(makeSlice(parsedBuf.c_data(), parsedBuf.size()>50?50:parsedBuf.size(),0)) << std::endl; std::cerr << Exiv2::Internal::binaryToString(makeSlice(parsedBuf.c_data(), parsedBuf.size()>50?50:parsedBuf.size(),0)) << std::endl;
#endif #endif
if ( parsedBuf.size() ) { if (!parsedBuf.empty()) {
if ( bExif ) { if ( bExif ) {
// create memio object with the data, then print the structure // create memio object with the data, then print the structure
MemIo p(parsedBuf.c_data(6), parsedBuf.size()-6); 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 DataBuf s(dataBuf.size()+1); // allocate buffer with an extra byte
s.copyBytes(0,dataBuf.c_data(),dataBuf.size());// copy in the dataBuf s.copyBytes(0,dataBuf.c_data(),dataBuf.size());// copy in the dataBuf
s.write_uint8(dataBuf.size(), 0); // nul terminate it s.write_uint8(dataBuf.size(), 0); // nul terminate it
@ -621,8 +621,7 @@ namespace Exiv2 {
{ {
// Update IPTC data to a new PNG chunk // Update IPTC data to a new PNG chunk
DataBuf newPsData = Photoshop::setIptcIrb(nullptr, 0, iptcData_); DataBuf newPsData = Photoshop::setIptcIrb(nullptr, 0, iptcData_);
if (newPsData.size() > 0) if (!newPsData.empty()) {
{
std::string rawIptc(newPsData.c_str(), newPsData.size()); std::string rawIptc(newPsData.c_str(), newPsData.size());
std::string chunk = PngChunk::makeMetadataChunk(rawIptc, mdIptc); std::string chunk = PngChunk::makeMetadataChunk(rawIptc, mdIptc);
if (outIo.write(reinterpret_cast<const byte*>(chunk.data()), chunk.size()) != chunk.size()) { if (outIo.write(reinterpret_cast<const byte*>(chunk.data()), chunk.size()) != chunk.size()) {

@ -250,7 +250,7 @@ namespace Exiv2 {
throw Error(kerFailedToReadImageData); throw Error(kerFailedToReadImageData);
ByteOrder bo = ExifParser::decode(exifData_, rawExif.c_data(), rawExif.size()); ByteOrder bo = ExifParser::decode(exifData_, rawExif.c_data(), rawExif.size());
setByteOrder(bo); setByteOrder(bo);
if (rawExif.size() > 0 && byteOrder() == invalidByteOrder) { if (!rawExif.empty() && byteOrder() == invalidByteOrder) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Failed to decode Exif metadata.\n"; EXV_WARNING << "Failed to decode Exif metadata.\n";
#endif #endif
@ -579,7 +579,7 @@ namespace Exiv2 {
if (iptcData.count() > 0) { if (iptcData.count() > 0) {
DataBuf rawIptc = IptcParser::encode(iptcData); DataBuf rawIptc = IptcParser::encode(iptcData);
if (rawIptc.size() > 0) { if (!rawIptc.empty()) {
#ifdef EXIV2_DEBUG_MESSAGES #ifdef EXIV2_DEBUG_MESSAGES
std::cerr << std::hex << "write: resourceId: " << kPhotoshopResourceID_IPTC_NAA << "\n"; std::cerr << std::hex << "write: resourceId: " << kPhotoshopResourceID_IPTC_NAA << "\n";
std::cerr << std::dec << "Writing IPTC_NAA: size: " << rawIptc.size() << "\n"; std::cerr << std::dec << "Writing IPTC_NAA: size: " << rawIptc.size() << "\n";

@ -1391,7 +1391,7 @@ namespace Exiv2::Internal {
cryptFct = sonyTagEncipher; cryptFct = sonyTagEncipher;
} }
DataBuf buf = cryptFct(tag(), mio.mmap(), static_cast<uint32_t>(mio.size()), pRoot_); DataBuf buf = cryptFct(tag(), mio.mmap(), static_cast<uint32_t>(mio.size()), pRoot_);
if ( buf.size()) { if (!buf.empty()) {
mio.seek(0,Exiv2::FileIo::beg); mio.seek(0,Exiv2::FileIo::beg);
mio.write(buf.c_data(), buf.size()); mio.write(buf.c_data(), buf.size());
} }

@ -599,7 +599,7 @@ namespace Exiv2::Internal {
if (pos != exifData_.end()) { if (pos != exifData_.end()) {
irbKey.setIdx(pos->idx()); irbKey.setIdx(pos->idx());
} }
if (rawIptc.size() != 0 && (del || pos == exifData_.end())) { if (!rawIptc.empty() && (del || pos == exifData_.end())) {
auto value = Value::create(unsignedLong); auto value = Value::create(unsignedLong);
DataBuf buf; DataBuf buf;
if (rawIptc.size() % 4 != 0) { if (rawIptc.size() % 4 != 0) {
@ -622,7 +622,7 @@ namespace Exiv2::Internal {
pos->value().copy(irbBuf.data(), invalidByteOrder); pos->value().copy(irbBuf.data(), invalidByteOrder);
irbBuf = Photoshop::setIptcIrb(irbBuf.c_data(), irbBuf.size(), iptcData_); irbBuf = Photoshop::setIptcIrb(irbBuf.c_data(), irbBuf.size(), iptcData_);
exifData_.erase(pos); exifData_.erase(pos);
if (irbBuf.size() != 0) { if (!irbBuf.empty()) {
auto value = Value::create(unsignedByte); auto value = Value::create(unsignedByte);
value->read(irbBuf.data(), static_cast<long>(irbBuf.size()), invalidByteOrder); value->read(irbBuf.data(), static_cast<long>(irbBuf.size()), invalidByteOrder);
Exifdatum iptcDatum(irbKey, value.get()); Exifdatum iptcDatum(irbKey, value.get());
@ -815,7 +815,7 @@ namespace Exiv2::Internal {
if (cryptFct != nullptr) { if (cryptFct != nullptr) {
const byte* pData = object->pData(); const byte* pData = object->pData();
DataBuf buf = cryptFct(object->tag(), pData, size, pRoot_); DataBuf buf = cryptFct(object->tag(), pData, size, pRoot_);
if (buf.size() > 0) { if (!buf.empty()) {
pData = buf.c_data(); pData = buf.c_data();
size = static_cast<int32_t>(buf.size()); size = static_cast<int32_t>(buf.size());
} }
@ -930,7 +930,7 @@ namespace Exiv2::Internal {
std::cerr << "Writing data area for " << key << "\n"; std::cerr << "Writing data area for " << key << "\n";
#endif #endif
DataBuf buf = object->pValue()->dataArea(); DataBuf buf = object->pValue()->dataArea();
if ( buf.size() > 0 ) { if (!buf.empty()) {
memcpy(object->pDataArea_, buf.c_data(), buf.size()); memcpy(object->pDataArea_, buf.c_data(), buf.size());
if (object->sizeDataArea_ > static_cast<size_t>(buf.size())) { if (object->sizeDataArea_ > static_cast<size_t>(buf.size())) {
memset(object->pDataArea_ + buf.size(), memset(object->pDataArea_ + buf.size(),
@ -1639,7 +1639,8 @@ namespace Exiv2::Internal {
std::shared_ptr<DataBuf> buf = std::make_shared<DataBuf>( std::shared_ptr<DataBuf> buf = std::make_shared<DataBuf>(
cryptFct(object->tag(), pData, size, pRoot_) cryptFct(object->tag(), pData, size, pRoot_)
); );
if (buf->size() > 0) object->setData(buf); if (!buf->empty())
object->setData(buf);
} }
const ArrayDef* defs = object->def(); const ArrayDef* defs = object->def();

Loading…
Cancel
Save