diff --git a/app/actions.cpp b/app/actions.cpp index 46130052..e07f0835 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -362,7 +362,7 @@ namespace Action { if (md != exifData.end()) { md->write(std::cout, &exifData); rc = 1; - } else if (nullptr != easyAccessFctFallback) { + } else if (easyAccessFctFallback) { md = easyAccessFctFallback(exifData); if (md != exifData.end()) { md->write(std::cout, &exifData); @@ -1337,7 +1337,7 @@ namespace Action { if (metadatum) { value = metadatum->getValue(); } - if (value.get() == nullptr || (modifyCmd.explicitType_ && modifyCmd.typeId_ != value->typeId())) { + if (!value || (modifyCmd.explicitType_ && modifyCmd.typeId_ != value->typeId())) { value = Exiv2::Value::create(modifyCmd.typeId_); } int rc = value->read(modifyCmd.value_); @@ -1711,7 +1711,7 @@ namespace { if (timeStr.length() < 19) return 2; if ( (timeStr[4] != ':' && timeStr[4] != '-') || (timeStr[7] != ':' && timeStr[7] != '-') || timeStr[10] != ' ' || timeStr[13] != ':' || timeStr[16] != ':') return 3; - if (nullptr == tm) + if (!tm) return 4; std::memset(tm, 0x0, sizeof(struct tm)); tm->tm_isdst = -1; @@ -1745,7 +1745,7 @@ namespace { std::string tm2Str(const struct tm* tm) { - if (nullptr == tm) + if (!tm) return ""; std::ostringstream os; diff --git a/app/getopt.cpp b/app/getopt.cpp index 9dff95de..975b9ed6 100644 --- a/app/getopt.cpp +++ b/app/getopt.cpp @@ -105,7 +105,7 @@ namespace Util { if (c == -1) { break; } - errcnt_ += option(c, Util::optarg == nullptr ? "" : Util::optarg, Util::optopt); + errcnt_ += option(c, Util::optarg ? Util::optarg : "", Util::optopt); if (c == '?' ) { break; } diff --git a/samples/addmoddel.cpp b/samples/addmoddel.cpp index b858f7a6..972e848e 100644 --- a/samples/addmoddel.cpp +++ b/samples/addmoddel.cpp @@ -99,7 +99,7 @@ try { v = pos->getValue(); // Downcast the Value pointer to its actual type auto prv = dynamic_cast(v.get()); - if (prv == nullptr) + if (!prv) throw Exiv2::Error(Exiv2::kerErrorMessage, "Downcast failed"); rv = Exiv2::URationalValue(*prv); diff --git a/src/basicio.cpp b/src/basicio.cpp index 89a99499..603ba004 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -162,7 +162,7 @@ namespace Exiv2 { long offset = std::ftell(fp_); if (offset == -1) return -1; // 'Manual' open("r+b") to avoid munmap() - if (fp_ != nullptr) { + if (fp_) { std::fclose(fp_); fp_ = nullptr; } @@ -198,7 +198,7 @@ namespace Exiv2 { int FileIo::munmap() { int rc = 0; - if (p_->pMappedArea_ != nullptr) { + if (p_->pMappedArea_) { #if defined EXV_HAVE_MMAP && defined EXV_HAVE_MUNMAP if (::munmap(p_->pMappedArea_, p_->mappedLength_) != 0) { rc = 1; @@ -221,7 +221,7 @@ namespace Exiv2 { #endif } if (p_->isWriteable_) { - if (p_->fp_ != nullptr) + if (p_->fp_) p_->switchMode(Impl::opRead); p_->isWriteable_ = false; } @@ -480,7 +480,7 @@ namespace Exiv2 { size_t FileIo::size() const { // Flush and commit only if the file is open for writing - if (p_->fp_ != nullptr && (p_->openMode_.at(0) != 'r' || p_->openMode_.at(1) == '+')) { + if (p_->fp_ && (p_->openMode_.at(0) != 'r' || p_->openMode_.at(1) == '+')) { std::fflush(p_->fp_); #if defined WIN32 && !defined __CYGWIN__ // This is required on msvcrt before stat after writing to a file @@ -522,7 +522,7 @@ namespace Exiv2 { int rc = 0; if (munmap() != 0) rc = 2; - if (p_->fp_ != nullptr) { + if (p_->fp_) { if (std::fclose(p_->fp_) != 0) rc |= 1; p_->fp_ = nullptr; @@ -560,10 +560,7 @@ namespace Exiv2 { return getc(p_->fp_); } - int FileIo::error() const - { - return p_->fp_ != nullptr ? ferror(p_->fp_) : 0; - } + int FileIo::error() const { return p_->fp_ ? ferror(p_->fp_) : 0; } bool FileIo::eof() const { @@ -633,7 +630,7 @@ namespace Exiv2 { //! @param num The size of data void populate (byte* source, size_t num) { - assert(source != nullptr); + assert(source); size_ = num; data_ = new byte [size_]; type_ = bMemory; @@ -688,10 +685,10 @@ namespace Exiv2 { // Minimum size for 1st block size_t size = std::max(blockSize * (1 + need / blockSize), size_); auto data = static_cast(std::malloc(size)); - if (data == nullptr) { + if (!data) { throw Error(kerMallocFailed); } - if (data_ != nullptr) { + if (data_) { std::memcpy(data, data_, size_); } data_ = data; @@ -706,7 +703,7 @@ namespace Exiv2 { // Allocate in blocks size_t want = blockSize * (1 + need / blockSize ); data_ = static_cast(std::realloc(data_, want)); - if (data_ == nullptr) { + if (!data_) { throw Error(kerMallocFailed); } sizeAlloced_ = want; @@ -736,7 +733,7 @@ namespace Exiv2 { { p_->reserve(wcount); assert(p_->isMalloced_); - if (data != nullptr) { + if (data) { std::memcpy(&p_->data_[p_->idx_], data, wcount); } p_->idx_ += wcount; @@ -1320,7 +1317,7 @@ namespace Exiv2 { size_t totalRead = 0; do { byte* data = p_->blocksMap_[iBlock++].getData(); - if (data == nullptr) + if (!data) data = fakeData; size_t blockR = std::min(allow, p_->blockSize_ - startPos); std::memcpy(&buf[totalRead], &data[startPos], blockR); @@ -1845,7 +1842,7 @@ namespace Exiv2 { size_t curlWriter(char* data, size_t size, size_t nmemb, std::string* writerData) { - if (writerData == nullptr) + if (!writerData) return 0; writerData->append(data, size*nmemb); return size * nmemb; diff --git a/src/convert.cpp b/src/convert.cpp index cafb1a02..ff2b26f6 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -523,7 +523,7 @@ namespace Exiv2 { if (!prepareXmpTarget(to)) return; const auto cv = dynamic_cast(&pos->value()); - if (cv == nullptr) { + if (!cv) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Failed to convert " << from << " to " << to << "\n"; #endif diff --git a/src/crwimage.cpp b/src/crwimage.cpp index 60ce8de3..143fa2b5 100644 --- a/src/crwimage.cpp +++ b/src/crwimage.cpp @@ -71,7 +71,7 @@ namespace Exiv2 { #ifdef EXIV2_DEBUG_MESSAGES std::cerr << "Reading CRW file " << io_->path() << "\n"; #endif - if (io_->open() != 0) { + if (io_->open()) { throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); @@ -121,8 +121,8 @@ namespace Exiv2 { void CrwParser::decode(CrwImage* pCrwImage, const byte* pData, uint32_t size) { - assert(pCrwImage != 0); - assert(pData != 0); + assert(pCrwImage); + assert(pData); // Parse the image, starting with a CIFF header component CiffHeader header; diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 7d9274ce..4c03d4a4 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -557,7 +557,7 @@ namespace Exiv2::Internal { CiffComponent* CiffHeader::findComponent(uint16_t crwTagId, uint16_t crwDir) const { - if (pRootDir_ == nullptr) + if (!pRootDir_) return nullptr; return pRootDir_->findComponent(crwTagId, crwDir); } // CiffHeader::findComponent @@ -639,7 +639,7 @@ namespace Exiv2::Internal { break; } } - if (cc_ == nullptr) { + if (!cc_) { // Directory doesn't exist yet, add it m_ = std::make_unique(csd.crwDir_, csd.parent_); cc_ = m_.get(); @@ -656,7 +656,7 @@ namespace Exiv2::Internal { break; } } - if (cc_ == nullptr) { + if (!cc_) { // Tag doesn't exist yet, add it m_ = std::make_unique(crwTagId, tag()); cc_ = m_.get(); @@ -952,7 +952,7 @@ namespace Exiv2::Internal { void CrwMap::encode(CiffHeader* pHead, const Image& image) { for (auto&& crw : crwMapping_) { - if (crw.fromExif_ != nullptr) { + if (crw.fromExif_) { crw.fromExif_(image, &crw, pHead); } } diff --git a/src/datasets.cpp b/src/datasets.cpp index fb85b25c..d1e41b01 100644 --- a/src/datasets.cpp +++ b/src/datasets.cpp @@ -537,7 +537,7 @@ namespace Exiv2 { void IptcDataSets::dataSetList(std::ostream& os) { for (auto&& record : records_) { - for (int j = 0; record != nullptr && record[j].number_ != 0xffff; ++j) { + for (int j = 0; record && record[j].number_ != 0xffff; ++j) { os << record[j] << "\n"; } } diff --git a/src/exif.cpp b/src/exif.cpp index b470f959..9cef2b7e 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -166,9 +166,9 @@ namespace Exiv2 { Exifdatum::Exifdatum(const Exifdatum& rhs) : Metadatum(rhs) { - if (rhs.key_.get() != nullptr) + if (rhs.key_) key_ = rhs.key_->clone(); // deep copy - if (rhs.value_.get() != nullptr) + if (rhs.value_) value_ = rhs.value_->clone(); // deep copy } @@ -207,7 +207,7 @@ namespace Exiv2 { const Value& Exifdatum::value() const { - if (value_.get() == nullptr) + if (!value_) throw Error(kerValueNotSet); return *value_; } @@ -218,11 +218,11 @@ namespace Exiv2 { Metadatum::operator=(rhs); key_.reset(); - if (rhs.key_.get() != nullptr) + if (rhs.key_) key_ = rhs.key_->clone(); // deep copy value_.reset(); - if (rhs.value_.get() != nullptr) + if (rhs.value_) value_ = rhs.value_->clone(); // deep copy return *this; @@ -278,72 +278,36 @@ namespace Exiv2 { int Exifdatum::setValue(const std::string& value) { - if (value_.get() == nullptr) { + if (!value_) { TypeId type = key_->defaultTypeId(); value_ = Value::create(type); } return value_->read(value); } - int Exifdatum::setDataArea(const byte* buf, size_t len) - { - return value_.get() == nullptr ? -1 : value_->setDataArea(buf, len); - } + int Exifdatum::setDataArea(const byte* buf, size_t len) { return value_ ? value_->setDataArea(buf, len) : -1; } - std::string Exifdatum::key() const - { - return key_.get() == nullptr ? "" : key_->key(); - } + std::string Exifdatum::key() const { return key_ ? key_->key() : ""; } - const char* Exifdatum::familyName() const - { - return key_.get() == nullptr ? "" : key_->familyName(); - } + const char* Exifdatum::familyName() const { return key_ ? key_->familyName() : ""; } - std::string Exifdatum::groupName() const - { - return key_.get() == nullptr ? "" : key_->groupName(); - } + std::string Exifdatum::groupName() const { return key_ ? key_->groupName() : ""; } - std::string Exifdatum::tagName() const - { - return key_.get() == nullptr ? "" : key_->tagName(); - } + std::string Exifdatum::tagName() const { return key_ ? key_->tagName() : ""; } - std::string Exifdatum::tagLabel() const - { - return key_.get() == nullptr ? "" : key_->tagLabel(); - } + std::string Exifdatum::tagLabel() const { return key_ ? key_->tagLabel() : ""; } - uint16_t Exifdatum::tag() const - { - return key_.get() == nullptr ? 0xffff : key_->tag(); - } + uint16_t Exifdatum::tag() const { return key_ ? key_->tag() : 0xffff; } - int Exifdatum::ifdId() const - { - return key_.get() == nullptr ? ifdIdNotSet : key_->ifdId(); - } + int Exifdatum::ifdId() const { return key_ ? key_->ifdId() : ifdIdNotSet; } - const char* Exifdatum::ifdName() const - { - return key_.get() == nullptr ? "" : Internal::ifdName(static_cast(key_->ifdId())); - } + const char* Exifdatum::ifdName() const { return key_ ? Internal::ifdName(Internal::IfdId(key_->ifdId())) : ""; } - int Exifdatum::idx() const - { - return key_.get() == nullptr ? 0 : key_->idx(); - } + int Exifdatum::idx() const { return key_ ? key_->idx() : 0; } - long Exifdatum::copy(byte* buf, ByteOrder byteOrder) const - { - return value_.get() == nullptr ? 0 : value_->copy(buf, byteOrder); - } + long Exifdatum::copy(byte* buf, ByteOrder byteOrder) const { return value_ ? value_->copy(buf, byteOrder) : 0; } - TypeId Exifdatum::typeId() const - { - return value_.get() == nullptr ? invalidTypeId : value_->typeId(); - } + TypeId Exifdatum::typeId() const { return value_ ? value_->typeId() : invalidTypeId; } const char* Exifdatum::typeName() const { @@ -355,55 +319,25 @@ namespace Exiv2 { return static_cast(TypeInfo::typeSize(typeId())); } - size_t Exifdatum::count() const - { - return value_.get() == nullptr ? 0 : value_->count(); - } + size_t Exifdatum::count() const { return value_ ? value_->count() : 0; } - long Exifdatum::size() const - { - return value_.get() == nullptr ? 0 : static_cast(value_->size()); - } + long Exifdatum::size() const { return value_ ? static_cast(value_->size()) : 0; } - std::string Exifdatum::toString() const - { - return value_.get() == nullptr ? "" : value_->toString(); - } + std::string Exifdatum::toString() const { return value_ ? value_->toString() : ""; } - std::string Exifdatum::toString(long n) const - { - return value_.get() == nullptr ? "" : value_->toString(n); - } + std::string Exifdatum::toString(long n) const { return value_ ? value_->toString(n) : ""; } - int64_t Exifdatum::toInt64(long n) const - { - return value_.get() == nullptr ? -1 : value_->toInt64(n); - } + int64_t Exifdatum::toInt64(long n) const { return value_ ? value_->toInt64(n) : -1; } - float Exifdatum::toFloat(long n) const - { - return value_.get() == nullptr ? -1 : value_->toFloat(n); - } + float Exifdatum::toFloat(long n) const { return value_ ? value_->toFloat(n) : -1; } - Rational Exifdatum::toRational(long n) const - { - return value_.get() == nullptr ? Rational(-1, 1) : value_->toRational(n); - } + Rational Exifdatum::toRational(long n) const { return value_ ? value_->toRational(n) : Rational(-1, 1); } - Value::UniquePtr Exifdatum::getValue() const - { - return value_.get() == nullptr ? nullptr : value_->clone(); - } + Value::UniquePtr Exifdatum::getValue() const { return value_ ? value_->clone() : nullptr; } - size_t Exifdatum::sizeDataArea() const - { - return value_.get() == nullptr ? 0 : value_->sizeDataArea(); - } + size_t Exifdatum::sizeDataArea() const { return value_ ? value_->sizeDataArea() : 0; } - DataBuf Exifdatum::dataArea() const - { - return value_.get() == nullptr ? DataBuf(nullptr, 0) : value_->dataArea(); - } + DataBuf Exifdatum::dataArea() const { return value_ ? value_->dataArea() : DataBuf(nullptr, 0); } ExifThumbC::ExifThumbC(const ExifData& exifData) : exifData_(exifData) diff --git a/src/image.cpp b/src/image.cpp index 9197d9e6..3bd70246 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -796,7 +796,7 @@ namespace Exiv2 { bool ImageFactory::checkType(ImageType type, BasicIo& io, bool advance) { const Registry* r = find(registry, type); - if (nullptr != r) { + if (r) { return r->isThisType_(io, advance); } return false; @@ -909,7 +909,7 @@ namespace Exiv2 { // BasicIo instance does not need to be open const Registry* r = find(registry, type); - if (r == nullptr || type == ImageType::none) { + if (!r || type == ImageType::none) { return {}; } @@ -922,7 +922,7 @@ namespace Exiv2 { void append(Blob& blob, const byte* buf, size_t len) { if (len != 0) { - assert(buf != 0); + assert(buf); Blob::size_type size = blob.size(); if (blob.capacity() - size < len) { blob.reserve(size + 65536); diff --git a/src/ini.cpp b/src/ini.cpp index 1e005e47..f586c497 100755 --- a/src/ini.cpp +++ b/src/ini.cpp @@ -105,7 +105,7 @@ int Exiv2::ini_parse_stream(ini_reader reader, void* stream, ini_handler handler #endif /* Scan through stream line by line */ - while (reader(line, INI_MAX_LINE, stream) != nullptr) { + while (reader(line, INI_MAX_LINE, stream)) { lineno++; start = line; diff --git a/src/iptc.cpp b/src/iptc.cpp index ceeb0450..98e5dc30 100644 --- a/src/iptc.cpp +++ b/src/iptc.cpp @@ -72,66 +72,36 @@ namespace Exiv2 { Iptcdatum::Iptcdatum(const Iptcdatum& rhs) : Metadatum(rhs) { - if (rhs.key_.get() != nullptr) + if (rhs.key_) key_ = rhs.key_->clone(); // deep copy - if (rhs.value_.get() != nullptr) + if (rhs.value_) value_ = rhs.value_->clone(); // deep copy } - long Iptcdatum::copy(byte* buf, ByteOrder byteOrder) const - { - return value_.get() == nullptr ? 0 : value_->copy(buf, byteOrder); - } + long Iptcdatum::copy(byte* buf, ByteOrder byteOrder) const { return value_ ? value_->copy(buf, byteOrder) : 0; } std::ostream& Iptcdatum::write(std::ostream& os, const ExifData*) const { return os << value(); } - std::string Iptcdatum::key() const - { - return key_.get() == nullptr ? "" : key_->key(); - } + std::string Iptcdatum::key() const { return key_ ? key_->key() : ""; } - std::string Iptcdatum::recordName() const - { - return key_.get() == nullptr ? "" : key_->recordName(); - } + std::string Iptcdatum::recordName() const { return key_ ? key_->recordName() : ""; } - uint16_t Iptcdatum::record() const - { - return key_.get() == nullptr ? 0 : key_->record(); - } + uint16_t Iptcdatum::record() const { return key_ ? key_->record() : 0; } - const char* Iptcdatum::familyName() const - { - return key_.get() == nullptr ? "" : key_->familyName(); - } + const char* Iptcdatum::familyName() const { return key_ ? key_->familyName() : ""; } - std::string Iptcdatum::groupName() const - { - return key_.get() == nullptr ? "" : key_->groupName(); - } + std::string Iptcdatum::groupName() const { return key_ ? key_->groupName() : ""; } - std::string Iptcdatum::tagName() const - { - return key_.get() == nullptr ? "" : key_->tagName(); - } + std::string Iptcdatum::tagName() const { return key_ ? key_->tagName() : ""; } - std::string Iptcdatum::tagLabel() const - { - return key_.get() == nullptr ? "" : key_->tagLabel(); - } + std::string Iptcdatum::tagLabel() const { return key_ ? key_->tagLabel() : ""; } - uint16_t Iptcdatum::tag() const - { - return key_.get() == nullptr ? 0 : key_->tag(); - } + uint16_t Iptcdatum::tag() const { return key_ ? key_->tag() : 0; } - TypeId Iptcdatum::typeId() const - { - return value_.get() == nullptr ? invalidTypeId : value_->typeId(); - } + TypeId Iptcdatum::typeId() const { return value_ ? value_->typeId() : invalidTypeId; } const char* Iptcdatum::typeName() const { @@ -143,49 +113,25 @@ namespace Exiv2 { return static_cast(TypeInfo::typeSize(typeId())); } - size_t Iptcdatum::count() const - { - return value_.get() == nullptr ? 0 : value_->count(); - } + size_t Iptcdatum::count() const { return value_ ? value_->count() : 0; } - long Iptcdatum::size() const - { - return value_.get() == nullptr ? 0 : static_cast(value_->size()); - } + long Iptcdatum::size() const { return value_ ? static_cast(value_->size()) : 0; } - std::string Iptcdatum::toString() const - { - return value_.get() == nullptr ? "" : value_->toString(); - } + std::string Iptcdatum::toString() const { return value_ ? value_->toString() : ""; } - std::string Iptcdatum::toString(long n) const - { - return value_.get() == nullptr ? "" : value_->toString(n); - } + std::string Iptcdatum::toString(long n) const { return value_ ? value_->toString(n) : ""; } - int64_t Iptcdatum::toInt64(long n) const - { - return value_.get() == nullptr ? -1 : value_->toInt64(n); - } + int64_t Iptcdatum::toInt64(long n) const { return value_ ? value_->toInt64(n) : -1; } - float Iptcdatum::toFloat(long n) const - { - return value_.get() == nullptr ? -1 : value_->toFloat(n); - } + float Iptcdatum::toFloat(long n) const { return value_ ? value_->toFloat(n) : -1; } - Rational Iptcdatum::toRational(long n) const - { - return value_.get() == nullptr ? Rational(-1, 1) : value_->toRational(n); - } + Rational Iptcdatum::toRational(long n) const { return value_ ? value_->toRational(n) : Rational(-1, 1); } - Value::UniquePtr Iptcdatum::getValue() const - { - return value_.get() == nullptr ? nullptr : value_->clone(); - } + Value::UniquePtr Iptcdatum::getValue() const { return value_ ? value_->clone() : nullptr; } const Value& Iptcdatum::value() const { - if (value_.get() == nullptr) + if (!value_) throw Error(kerValueNotSet); return *value_; } @@ -196,11 +142,11 @@ namespace Exiv2 { Metadatum::operator=(rhs); key_.reset(); - if (rhs.key_.get() != nullptr) + if (rhs.key_) key_ = rhs.key_->clone(); // deep copy value_.reset(); - if (rhs.value_.get() != nullptr) + if (rhs.value_) value_ = rhs.value_->clone(); // deep copy return *this; @@ -234,7 +180,7 @@ namespace Exiv2 { int Iptcdatum::setValue(const std::string& value) { - if (value_.get() == nullptr) { + if (!value_) { TypeId type = IptcDataSets::dataSetType(tag(), record()); value_ = Value::create(type); } diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index cd638cfa..0079e7fd 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -173,11 +173,8 @@ namespace Exiv2::Internal { TiffComponent* tc = nullptr; const TiffMnRegistry* tmr = find(registry_, mnGroup); if (tmr) { - - if (tmr->newMnFct2_ == nullptr) { - + if (!tmr->newMnFct2_) { std::cout << "mnGroup = " << mnGroup << "\n"; - } assert(tmr->newMnFct2_); @@ -1105,7 +1102,7 @@ namespace Exiv2::Internal { { if (size < 4) return -1; const NikonArrayIdx* aix = find(nikonArrayIdx, NikonArrayIdx::Key(tag, reinterpret_cast(pData), size)); - return aix == nullptr ? -1 : aix->idx_; + return aix ? aix->idx_ : -1; } DataBuf nikonCrypt(uint16_t tag, const byte* pData, uint32_t size, TiffComponent* const pRoot) @@ -1114,7 +1111,8 @@ namespace Exiv2::Internal { if (size < 4) return buf; const NikonArrayIdx* nci = find(nikonArrayIdx, NikonArrayIdx::Key(tag, reinterpret_cast(pData), size)); - if (nci == nullptr || nci->start_ == NA || size <= nci->start_) return buf; + if (!nci || nci->start_ == NA || size <= nci->start_) + return buf; // Find Exif.Nikon3.ShutterCount TiffFinder finder(0x00a7, nikon3Id); diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index fafaf189..8a7187fc 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -2621,32 +2621,30 @@ fmountlens[] = { /* if no meta obj is provided, try to use the value param that *may* * be the pre-parsed lensid */ - if (metadata == nullptr) - { - const auto vid = static_cast(value.toInt64(0)); +if (!metadata) { + const auto vid = static_cast(value.toInt64(0)); - /* the 'FMntLens' name is added to the anonymous struct for - * fmountlens[] - * - * remember to name the struct when importing/updating the lens info - * from: - * - * www.rottmerhusen.com/objektives/lensid/files/c-header/fmountlens4.h - */ - const struct FMntLens* pf = fmountlens; - while (pf->lid && pf->lensname) { - if (pf->lid == vid) { - break; - } - ++pf; - } - - if (pf->lensname == nullptr) { - return os << value; - } - return os << pf->manuf << " " << pf->lensname; + /* the 'FMntLens' name is added to the anonymous struct for + * fmountlens[] + * + * remember to name the struct when importing/updating the lens info + * from: + * + * www.rottmerhusen.com/objektives/lensid/files/c-header/fmountlens4.h + */ + const struct FMntLens* pf = fmountlens; + while (pf->lid && pf->lensname) { + if (pf->lid == vid) { + break; } + ++pf; + } + if (!pf->lensname) { + return os << value; + } + return os << pf->manuf << " " << pf->lensname; +} byte raw[] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; @@ -2676,7 +2674,7 @@ fmountlens[] = { } raw[7] = static_cast(md->toInt64()); - for (int i = 0; fmountlens[i].lensname != nullptr; ++i) { + for (int i = 0; fmountlens[i].lensname; ++i) { if ( raw[0] == fmountlens[i].lid ) { // #1034 const std::string undefined("undefined") ; diff --git a/src/olympusmn_int.cpp b/src/olympusmn_int.cpp index c04ffa04..46f55bb5 100644 --- a/src/olympusmn_int.cpp +++ b/src/olympusmn_int.cpp @@ -1630,7 +1630,7 @@ value, const ExifData* metadata) bool E3_E30model = false; - if (metadata != nullptr) { + if (metadata) { auto pos = metadata->findKey(ExifKey("Exif.Image.Model")); if (pos != metadata->end() && pos->count() != 0) { std::string model = pos->toString(); diff --git a/src/preview.cpp b/src/preview.cpp index 32418dd3..2cd0a0fb 100644 --- a/src/preview.cpp +++ b/src/preview.cpp @@ -366,7 +366,7 @@ namespace { auto loader = loaderList_[id].create_(id, image, loaderList_[id].parIdx_); - if (loader.get() && !loader->valid()) + if (loader && !loader->valid()) loader.reset(); return loader; diff --git a/src/properties.cpp b/src/properties.cpp index 6cf00671..2fd90a47 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -4025,7 +4025,8 @@ namespace Exiv2 { { std::lock_guard scoped_read_lock(mutex_); const XmpNsInfo* xn = lookupNsRegistryUnsafe(XmpNsInfo::Prefix(prefix)); - if (xn != nullptr) return xn->ns_; + if (xn) + return xn->ns_; return nsInfoUnsafe(prefix)->ns_; } @@ -4069,7 +4070,7 @@ namespace Exiv2 { const XmpPropertyInfo* pl = propertyList(prefix); if (!pl) return nullptr; const XmpPropertyInfo* pi = nullptr; - for (int j = 0; pl[j].name_ != nullptr; ++j) { + for (int j = 0; pl[j].name_; ++j) { if (0 == strcmp(pl[j].name_, property.c_str())) { pi = pl + j; break; @@ -4116,7 +4117,7 @@ namespace Exiv2 { { const XmpPropertyInfo* pl = propertyList(prefix); if (pl) { - for (int i = 0; pl[i].name_ != nullptr; ++i) { + for (int i = 0; pl[i].name_; ++i) { os << pl[i]; } } diff --git a/src/tags.cpp b/src/tags.cpp index 8badc90f..45a0bf25 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -102,7 +102,7 @@ namespace Exiv2 { const char* ExifTags::sectionName(const ExifKey& key) { const TagInfo* ti = tagInfo(key.tag(), static_cast(key.ifdId())); - if (ti == nullptr) + if (!ti) return sectionInfo[unknownTag.sectionId_].name_; return sectionInfo[ti->sectionId_].name_; } @@ -111,7 +111,7 @@ namespace Exiv2 { uint16_t ExifTags::defaultCount(const ExifKey& key) { const TagInfo* ti = tagInfo(key.tag(), static_cast(key.ifdId())); - if (ti == nullptr) + if (!ti) return unknownTag.count_; return ti->count_; } @@ -208,7 +208,7 @@ namespace Exiv2 { // DATA static constexpr auto familyName_ = "Exif"; //!< "Exif" - const TagInfo* tagInfo_{nullptr}; //!< Tag info + const TagInfo* tagInfo_{}; //!< Tag info uint16_t tag_{0}; //!< Tag value IfdId ifdId_{ifdIdNotSet}; //!< The IFD associated with this tag int idx_{0}; //!< Unique id of the Exif key in the image @@ -218,7 +218,7 @@ namespace Exiv2 { std::string ExifKey::Impl::tagName() const { - if (tagInfo_ != nullptr && tagInfo_->tag_ != 0xffff) { + if (tagInfo_ && tagInfo_->tag_ != 0xffff) { return tagInfo_->name_; } std::ostringstream os; @@ -254,7 +254,7 @@ namespace Exiv2 { uint16_t tag = tagNumber(tn, ifdId); // Get tag info tagInfo_ = tagInfo(tag, ifdId); - if (tagInfo_ == nullptr) + if (!tagInfo_) throw Error(kerInvalidKey, key); tag_ = tag; @@ -266,7 +266,7 @@ namespace Exiv2 { void ExifKey::Impl::makeKey(uint16_t tag, IfdId ifdId, const TagInfo* tagInfo) { - assert(tagInfo != 0); + assert(tagInfo); tagInfo_ = tagInfo; tag_ = tag; @@ -283,7 +283,7 @@ namespace Exiv2 { throw Error(kerInvalidIfdId, ifdId); } const TagInfo* ti = tagInfo(tag, ifdId); - if (ti == nullptr) { + if (!ti) { throw Error(kerInvalidIfdId, ifdId); } p_->groupName_ = groupName; @@ -346,21 +346,21 @@ namespace Exiv2 { std::string ExifKey::tagLabel() const { - if (p_->tagInfo_ == nullptr || p_->tagInfo_->tag_ == 0xffff) + if (!p_->tagInfo_ || p_->tagInfo_->tag_ == 0xffff) return ""; return _(p_->tagInfo_->title_); } std::string ExifKey::tagDesc() const { - if (p_->tagInfo_ == nullptr || p_->tagInfo_->tag_ == 0xffff) + if (!p_->tagInfo_ || p_->tagInfo_->tag_ == 0xffff) return ""; return _(p_->tagInfo_->desc_); } TypeId ExifKey::defaultTypeId() const { - if (p_->tagInfo_ == nullptr) + if (!p_->tagInfo_) return unknownTag.typeId_; return p_->tagInfo_->typeId_; } diff --git a/src/tags_int.cpp b/src/tags_int.cpp index d1617b9a..9a68d9bd 100644 --- a/src/tags_int.cpp +++ b/src/tags_int.cpp @@ -2472,7 +2472,7 @@ namespace Exiv2::Internal { { bool rc = false; const GroupInfo* ii = find(groupInfo, ifdId); - if (ii != nullptr && 0 == strcmp(ii->ifdName_, "Makernote")) { + if (ii && 0 == strcmp(ii->ifdName_, "Makernote")) { rc = true; } return rc; @@ -2509,7 +2509,7 @@ namespace Exiv2::Internal { void taglist(std::ostream& os, IfdId ifdId) { const TagInfo* ti = Internal::tagList(ifdId); - if (ti != nullptr) { + if (ti) { for (int k = 0; ti[k].tag_ != 0xffff; ++k) { os << ti[k] << "\n"; } @@ -2519,14 +2519,16 @@ namespace Exiv2::Internal { const TagInfo* tagList(IfdId ifdId) { const GroupInfo* ii = find(groupInfo, ifdId); - if (ii == nullptr || ii->tagList_ == nullptr) return nullptr; + if (!ii || !ii->tagList_) + return nullptr; return ii->tagList_(); } // tagList const TagInfo* tagInfo(uint16_t tag, IfdId ifdId) { const TagInfo* ti = tagList(ifdId); - if (ti == nullptr) return nullptr; + if (!ti) + return nullptr; int idx = 0; for (idx = 0; ti[idx].tag_ != 0xffff; ++idx) { if (ti[idx].tag_ == tag) break; @@ -2537,7 +2539,8 @@ namespace Exiv2::Internal { const TagInfo* tagInfo(const std::string& tagName, IfdId ifdId) { const TagInfo* ti = tagList(ifdId); - if (ti == nullptr) return nullptr; + if (!ti) + return nullptr; if (tagName.empty()) return nullptr; const char* tn = tagName.c_str(); for (int idx = 0; ti[idx].tag_ != 0xffff; ++idx) { @@ -2552,21 +2555,24 @@ namespace Exiv2::Internal { { IfdId ifdId = ifdIdNotSet; const GroupInfo* ii = find(groupInfo, GroupInfo::GroupName(groupName)); - if (ii != nullptr) ifdId = static_cast(ii->ifdId_); + if (ii) + ifdId = static_cast(ii->ifdId_); return ifdId; } const char* ifdName(IfdId ifdId) { const GroupInfo* ii = find(groupInfo, ifdId); - if (ii == nullptr) return groupInfo[0].ifdName_; + if (!ii) + return groupInfo[0].ifdName_; return ii->ifdName_; } const char* groupName(IfdId ifdId) { const GroupInfo* ii = find(groupInfo, ifdId); - if (ii == nullptr) return groupInfo[0].groupName_; + if (!ii) + return groupInfo[0].groupName_; return ii->groupName_; } @@ -2634,7 +2640,8 @@ namespace Exiv2::Internal { uint16_t tagNumber(const std::string& tagName, IfdId ifdId) { const TagInfo* ti = tagInfo(tagName, ifdId); - if (ti != nullptr && ti->tag_ != 0xffff) return ti->tag_; + if (ti && ti->tag_ != 0xffff) + return ti->tag_; if (!isHex(tagName, 4, "0x")) throw Error(kerInvalidTag, tagName, ifdId); std::istringstream is(tagName); uint16_t tag = 0; @@ -3289,7 +3296,7 @@ namespace Exiv2::Internal { const TagInfo* tagList(const std::string& groupName) { const GroupInfo* ii = find(groupInfo, GroupInfo::GroupName(groupName)); - if (ii == nullptr || ii->tagList_ == nullptr) { + if (!ii || !ii->tagList_) { return nullptr; } return ii->tagList_(); diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index f5e8ec73..8c1850b6 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -39,7 +39,7 @@ namespace Exiv2::Internal { IoWrapper::IoWrapper(BasicIo& io, const byte* pHeader, size_t size, OffsetWriter* pow) : io_(io), pHeader_(pHeader), size_(size), wroteHeader_(false), pow_(pow) { - if (pHeader_ == nullptr || size_ == 0) + if (!pHeader_ || size_ == 0) wroteHeader_ = true; } @@ -100,7 +100,7 @@ namespace Exiv2::Internal { arrayCfg_(arrayCfg), arrayDef_(arrayDef), defSize_(defSize) { - assert(arrayCfg != 0); + assert(arrayCfg); } TiffBinaryArray::TiffBinaryArray(uint16_t tag, IfdId group, const ArraySet* arraySet, int setSize, @@ -110,8 +110,8 @@ namespace Exiv2::Internal { arraySet_(arraySet), setSize_(setSize) { // We'll figure out the correct cfg later - assert(cfgSelFct != 0); - assert(arraySet_ != 0); + assert(cfgSelFct); + assert(arraySet_); } TiffBinaryElement::TiffBinaryElement(uint16_t tag, IfdId group) @@ -273,19 +273,19 @@ namespace Exiv2::Internal { pData_ = pData; size_ = size; storage_ = storage; - if (pData_ == nullptr) + if (!pData_) size_ = 0; } void TiffEntryBase::updateValue(Value::UniquePtr value, ByteOrder byteOrder) { - if (value.get() == nullptr) + if (!value) return; size_t newSize = value->size(); if (newSize > size_) { setData(std::make_shared(newSize)); } - if (pData_ != nullptr) { + if (pData_) { memset(pData_, 0x0, size_); } size_ = value->copy(pData_, byteOrder); @@ -295,7 +295,7 @@ namespace Exiv2::Internal { void TiffEntryBase::setValue(Value::UniquePtr value) { - if (value.get() == nullptr) + if (!value) return; tiffType_ = toTiffType(value->typeId()); count_ = value->count(); @@ -475,7 +475,7 @@ namespace Exiv2::Internal { bool TiffBinaryArray::initialize(IfdId group) { - if (arrayCfg_ != nullptr) + if (arrayCfg_) return true; // Not a complex array or already initialized for (int idx = 0; idx < setSize_; ++idx) { @@ -491,7 +491,7 @@ namespace Exiv2::Internal { bool TiffBinaryArray::initialize(TiffComponent* const pRoot) { - if (cfgSelFct_ == nullptr) + if (!cfgSelFct_) return true; // Not a complex array int idx = cfgSelFct_(tag(), pData(), TiffEntryBase::doSize(), pRoot); @@ -511,7 +511,7 @@ namespace Exiv2::Internal { bool TiffBinaryArray::updOrigDataBuf(const byte* pData, uint32_t size) { - assert(pData != 0); + assert(pData); if (origSize_ != size) return false; if (origData_ == pData) return true; @@ -580,18 +580,18 @@ namespace Exiv2::Internal { } } } - if (tc == nullptr) { + if (!tc) { std::unique_ptr atc; - if (tiffPath.size() == 1 && object.get() != nullptr) { + if (tiffPath.size() == 1 && object) { atc = std::move(object); } else { atc = TiffCreator::create(tpi.extendedTag(), tpi.group()); } - assert(atc.get() != 0); + assert(atc); // Prevent dangling sub-IFD tags: Do not add a sub-IFD component without children. // Todo: How to check before creating the component? - if (tiffPath.size() == 1 && dynamic_cast(atc.get()) != nullptr) + if (tiffPath.size() == 1 && dynamic_cast(atc.get())) return nullptr; if (tpi.extendedTag() == Tag::next) { @@ -626,8 +626,8 @@ namespace Exiv2::Internal { break; } } - if (tc == nullptr) { - if (tiffPath.size() == 1 && object.get() != nullptr) { + if (!tc) { + if (tiffPath.size() == 1 && object) { tc = addChild(std::move(object)); } else { auto atc = std::make_unique(tpi1.tag(), tpi2.group()); @@ -652,7 +652,7 @@ namespace Exiv2::Internal { } const TiffPathItem tpi2 = tiffPath.top(); tiffPath.push(tpi1); - if (mn_ == nullptr) { + if (!mn_) { mnGroup_ = tpi2.group(); mn_ = TiffMnCreator::create(tpi1.tag(), tpi1.group(), mnGroup_); assert(mn_); @@ -694,14 +694,14 @@ namespace Exiv2::Internal { } } } - if (tc == nullptr) { + if (!tc) { std::unique_ptr atc; - if (tiffPath.size() == 1 && object.get() != nullptr) { + if (tiffPath.size() == 1 && object) { atc = std::move(object); } else { atc = TiffCreator::create(tpi.extendedTag(), tpi.group()); } - assert(atc.get() != 0); + assert(atc); assert(tpi.extendedTag() != Tag::next); tc = addChild(std::move(atc)); setCount(static_cast(elements_.size())); @@ -958,7 +958,7 @@ namespace Exiv2::Internal { uint32_t TiffBinaryArray::doCount() const { - if (cfg() == nullptr || !decoded()) + if (!cfg() || !decoded()) return TiffEntryBase::doCount(); if (elements_.empty()) return 0; @@ -1310,7 +1310,7 @@ namespace Exiv2::Internal { uint32_t dataIdx, uint32_t& imageIdx) { - if (cfg() == nullptr || !decoded()) + if (!cfg() || !decoded()) return TiffEntryBase::doWrite(ioWrapper, byteOrder, offset, valueIdx, dataIdx, imageIdx); if (cfg()->byteOrder_ != invalidByteOrder) byteOrder = cfg()->byteOrder_; // Tags must be sorted in ascending order @@ -1636,7 +1636,7 @@ namespace Exiv2::Internal { uint32_t TiffBinaryArray::doSize() const { - if (cfg() == nullptr || !decoded()) + if (!cfg() || !decoded()) return TiffEntryBase::doSize(); if (elements_.empty()) return 0; @@ -1774,7 +1774,7 @@ namespace Exiv2::Internal { : group == gpsId ? Internal::gpsTagList() : nullptr; if ( tags ) { - for (size_t idx = 0; result == nullptr && tags[idx].tag_ != 0xffff; ++idx) { + for (size_t idx = 0; !result && tags[idx].tag_ != 0xffff; ++idx) { if ( tags[idx].tag_ == tag ) { result = tags+idx; } @@ -1819,16 +1819,16 @@ namespace Exiv2::Internal { bool cmpTagLt(TiffComponent const* lhs, TiffComponent const* rhs) { - assert(lhs != 0); - assert(rhs != 0); + assert(lhs); + assert(rhs); if (lhs->tag() != rhs->tag()) return lhs->tag() < rhs->tag(); return lhs->idx() < rhs->idx(); } bool cmpGroupLt(TiffComponent const* lhs, TiffComponent const* rhs) { - assert(lhs != 0); - assert(rhs != 0); + assert(lhs); + assert(rhs); return lhs->group() < rhs->group(); } diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp index 0a6302e4..4b33caa4 100644 --- a/src/tiffimage_int.cpp +++ b/src/tiffimage_int.cpp @@ -2017,7 +2017,7 @@ namespace Exiv2::Internal { do { tiffPath.push(TiffPathItem(extendedTag, group)); ts = find(tiffTreeStruct_, TiffTreeStruct::Key(root, group)); - assert(ts != 0); + assert(ts); extendedTag = ts->parentExtTag_; group = ts->parentGroup_; } while (!(ts->root_ == root && ts->group_ == ifdIdNotSet)); @@ -2102,13 +2102,12 @@ namespace Exiv2::Internal { parsedTree->accept(copier); } // Add entries from metadata to composite - TiffEncoder encoder(exifData, iptcData, xmpData, createdTree.get(), parsedTree == nullptr, &primaryGroups, - pHeader, findEncoderFct); + TiffEncoder encoder(exifData, iptcData, xmpData, createdTree.get(), !parsedTree, &primaryGroups, pHeader, + findEncoderFct); encoder.add(createdTree.get(), parsedTree.get(), root); // Write binary representation from the composite tree DataBuf header = pHeader->write(); auto tempIo = std::make_unique(); - assert(tempIo.get() != 0); IoWrapper ioWrapper(*tempIo, header.c_data(), header.size(), pOffsetWriter); auto imageIdx(uint32_t(-1)); createdTree->write(ioWrapper, @@ -2138,7 +2137,7 @@ namespace Exiv2::Internal { TiffHeaderBase* pHeader ) { - if (pData == nullptr || size == 0) + if (!pData || size == 0) return nullptr; if (!pHeader->read(pData, size) || pHeader->offset() >= size) { throw Error(kerNotAnImage, "TIFF"); @@ -2157,7 +2156,7 @@ namespace Exiv2::Internal { void TiffParserWorker::findPrimaryGroups(PrimaryGroups& primaryGroups, TiffComponent* pSourceDir) { - if (nullptr == pSourceDir) + if (!pSourceDir) return; const IfdId imageGroups[] = { @@ -2180,7 +2179,7 @@ namespace Exiv2::Internal { TiffFinder finder(0x00fe, imageGroup); pSourceDir->accept(finder); auto te = dynamic_cast(finder.result()); - const Value* pV = te != nullptr ? te->pValue() : nullptr; + const Value* pV = te ? te->pValue() : nullptr; if (pV && pV->typeId() == unsignedLong && pV->count() == 1 && (pV->toInt64() & 1) == 0) { primaryGroups.push_back(te->group()); } @@ -2398,7 +2397,7 @@ namespace Exiv2::Internal { ExifKey key(tag, groupName(group)); #endif // If there are primary groups and none matches group, we're done - if (pPrimaryGroups != nullptr && !pPrimaryGroups->empty() && + if (pPrimaryGroups && !pPrimaryGroups->empty() && std::find(pPrimaryGroups->begin(), pPrimaryGroups->end(), group) == pPrimaryGroups->end()) { #ifdef EXIV2_DEBUG_MESSAGES std::cerr << "Not an image tag: " << key << " (1)\n"; @@ -2407,7 +2406,7 @@ namespace Exiv2::Internal { } // All tags of marked primary groups other than IFD0 are considered // image tags. That should take care of NEFs until we know better. - if (pPrimaryGroups != nullptr && !pPrimaryGroups->empty() && group != ifd0Id) { + if (pPrimaryGroups && !pPrimaryGroups->empty() && group != ifd0Id) { #ifdef EXIV2_DEBUG_MESSAGES ExifKey key(tag, groupName(group)); std::cerr << "Image tag: " << key << " (2)\n"; diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index ddd5c5e6..16b01263 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -167,14 +167,14 @@ namespace Exiv2::Internal { pHeader_(pHeader), pPrimaryGroups_(pPrimaryGroups) { - assert(pRoot_ != 0); - assert(pHeader_ != 0); - assert(pPrimaryGroups_ != 0); + assert(pRoot_); + assert(pHeader_); + assert(pPrimaryGroups_); } void TiffCopier::copyObject(TiffComponent* object) { - assert(object != 0); + assert(object); if (pHeader_->isImageTag(object->tag(), object->group(), pPrimaryGroups_)) { auto clone = object->clone(); @@ -253,7 +253,7 @@ namespace Exiv2::Internal { findDecoderFct_(findDecoderFct), decodedIptc_(false) { - assert(pRoot != 0); + assert(pRoot); // #1402 Fujifilm RAF. Search for the make // Find camera make in existing metadata (read from the JPEG) @@ -309,7 +309,7 @@ namespace Exiv2::Internal { void TiffDecoder::visitIfdMakernote(TiffIfdMakernote* object) { - assert(object != 0); + assert(object); exifData_["Exif.MakerNote.Offset"] = object->mnOffset(); switch (object->byteOrder()) { @@ -502,7 +502,7 @@ namespace Exiv2::Internal { void TiffDecoder::decodeTiffEntry(const TiffEntryBase* object) { - assert(object != 0); + assert(object); // Don't decode the entry if value is not set if (!object->pValue()) return; @@ -518,7 +518,7 @@ namespace Exiv2::Internal { void TiffDecoder::decodeStdTiffEntry(const TiffEntryBase* object) { - assert(object != 0); + assert(object); ExifKey key(object->tag(), groupName(object->group())); key.setIdx(object->idx()); exifData_.add(key, object->pValue()); @@ -527,7 +527,7 @@ namespace Exiv2::Internal { void TiffDecoder::visitBinaryArray(TiffBinaryArray* object) { - if (object->cfg() == nullptr || !object->decoded()) { + if (!object->cfg() || !object->decoded()) { decodeTiffEntry(object); } } @@ -553,9 +553,9 @@ namespace Exiv2::Internal { dirty_(false), writeMethod_(wmNonIntrusive) { - assert(pRoot != 0); - assert(pPrimaryGroups != 0); - assert(pHeader != 0); + assert(pRoot); + assert(pPrimaryGroups); + assert(pHeader); byteOrder_ = pHeader->byteOrder(); origByteOrder_ = byteOrder_; @@ -699,7 +699,7 @@ namespace Exiv2::Internal { void TiffEncoder::visitDirectoryNext(TiffDirectory* object) { // Update type and count in IFD entries, in case they changed - assert(object != 0); + assert(object); byte* p = object->start() + 2; for (auto&& component : object->components_) { @@ -751,7 +751,7 @@ namespace Exiv2::Internal { void TiffEncoder::visitIfdMakernote(TiffIfdMakernote* object) { - assert(object != 0); + assert(object); auto pos = exifData_.findKey(ExifKey("Exif.MakerNote.ByteOrder")); if (pos != exifData_.end()) { @@ -787,16 +787,16 @@ namespace Exiv2::Internal { void TiffEncoder::visitBinaryArray(TiffBinaryArray* object) { - if (object->cfg() == nullptr || !object->decoded()) { + if (!object->cfg() || !object->decoded()) { encodeTiffComponent(object); } } void TiffEncoder::visitBinaryArrayEnd(TiffBinaryArray* object) { - assert(object != 0); + assert(object); - if (object->cfg() == nullptr || !object->decoded()) + if (!object->cfg() || !object->decoded()) return; int32_t size = object->TiffEntryBase::doSize(); if (size == 0) @@ -809,7 +809,7 @@ namespace Exiv2::Internal { if ( cryptFct == sonyTagDecipher ) { cryptFct = sonyTagEncipher; } - if (cryptFct != nullptr) { + if (cryptFct) { const byte* pData = object->pData(); DataBuf buf = cryptFct(object->tag(), pData, size, pRoot_); if (!buf.empty()) { @@ -841,11 +841,11 @@ namespace Exiv2::Internal { const Exifdatum* datum ) { - assert(object != 0); + assert(object); auto pos = exifData_.end(); const Exifdatum* ed = datum; - if (ed == nullptr) { + if (!ed) { // Non-intrusive writing: find matching tag ExifKey key(object->tag(), groupName(object->group())); pos = exifData_.findKey(key); @@ -1034,8 +1034,8 @@ namespace Exiv2::Internal { void TiffEncoder::encodeTiffEntryBase(TiffEntryBase* object, const Exifdatum* datum) { - assert(object != 0); - assert(datum != 0); + assert(object); + assert(datum); #ifdef EXIV2_DEBUG_MESSAGES bool tooLarge = false; @@ -1059,8 +1059,8 @@ namespace Exiv2::Internal { void TiffEncoder::encodeOffsetEntry(TiffEntryBase* object, const Exifdatum* datum) { - assert(object != 0); - assert(datum != 0); + assert(object); + assert(datum); uint32_t newSize = datum->size(); if (newSize > object->size_) { // value doesn't fit, encode for intrusive writing @@ -1089,7 +1089,7 @@ namespace Exiv2::Internal { uint32_t root ) { - assert(pRootDir != 0); + assert(pRootDir); writeMethod_ = wmIntrusive; pSourceTree_ = pSourceDir; @@ -1128,7 +1128,7 @@ namespace Exiv2::Internal { << std::hex << i->tag() << "\n"; } #endif - if (object != nullptr) { + if (object) { encodeTiffComponent(object, &(*i)); } } @@ -1170,7 +1170,7 @@ namespace Exiv2::Internal { { pState_ = &origState_; assert(pData_); - assert(size_ > 0); + assert(size_); } // TiffReader::TiffReader @@ -1181,7 +1181,7 @@ namespace Exiv2::Internal { void TiffReader::setMnState(const TiffRwState* state) { - if (state != nullptr) { + if (state) { // invalidByteOrder indicates 'no change' if (state->byteOrder() == invalidByteOrder) { mnState_ = TiffRwState(origState_.byteOrder(), state->baseOffset()); @@ -1207,7 +1207,7 @@ namespace Exiv2::Internal { void TiffReader::readDataEntryBase(TiffDataEntryBase* object) { - assert(object != 0); + assert(object); readTiffEntry(object); TiffFinder finder(object->szTag(), object->szGroup()); @@ -1235,7 +1235,7 @@ namespace Exiv2::Internal { void TiffReader::visitSizeEntry(TiffSizeEntry* object) { - assert(object != 0); + assert(object); readTiffEntry(object); TiffFinder finder(object->dtTag(), object->dtGroup()); @@ -1278,7 +1278,7 @@ namespace Exiv2::Internal { void TiffReader::visitDirectory(TiffDirectory* object) { - assert(object != 0); + assert(object); const byte* p = object->start(); assert(p >= pData_); @@ -1337,13 +1337,13 @@ namespace Exiv2::Internal { if (next) { tc = TiffCreator::create(Tag::next, object->group()); #ifndef SUPPRESS_WARNINGS - if (tc.get() == nullptr) { + if (!tc) { EXV_WARNING << "Directory " << groupName(object->group()) << " has an unexpected next pointer; ignored.\n"; } #endif } - if (tc.get()) { + if (tc) { if (baseOffset() + next > size_) { #ifndef SUPPRESS_WARNINGS EXV_ERROR << "Directory " << groupName(object->group()) @@ -1360,7 +1360,7 @@ namespace Exiv2::Internal { void TiffReader::visitSubIfd(TiffSubIfd* object) { - assert(object != 0); + assert(object); readTiffEntry(object); if ( (object->tiffType() == ttUnsignedLong || object->tiffType() == ttSignedLong @@ -1410,7 +1410,7 @@ namespace Exiv2::Internal { void TiffReader::visitMnEntry(TiffMnEntry* object) { - assert(object != 0); + assert(object); readTiffEntry(object); // Find camera make @@ -1434,7 +1434,7 @@ namespace Exiv2::Internal { void TiffReader::visitIfdMakernote(TiffIfdMakernote* object) { - assert(object != 0); + assert(object); object->setImageByteOrder(byteOrder()); // set the byte order for the image @@ -1472,7 +1472,7 @@ namespace Exiv2::Internal { void TiffReader::readTiffEntry(TiffEntryBase* object) { - assert(object != 0); + assert(object); byte* p = object->start(); assert(p >= pData_); @@ -1597,7 +1597,7 @@ namespace Exiv2::Internal { void TiffReader::visitBinaryArray(TiffBinaryArray* object) { - assert(object != 0); + assert(object); if (!postProc_) { // Defer reading children until after all other components are read, but @@ -1626,11 +1626,11 @@ namespace Exiv2::Internal { if (object->TiffEntryBase::doSize() == 0) return; if (!object->initialize(pRoot_)) return; const ArrayCfg* cfg = object->cfg(); - if (cfg == nullptr) + if (!cfg) return; const CryptFct cryptFct = cfg->cryptFct_; - if (cryptFct != nullptr) { + if (cryptFct) { const byte* pData = object->pData(); int32_t size = object->TiffEntryBase::doSize(); auto buf = std::make_shared(cryptFct(object->tag(), pData, size, pRoot_)); diff --git a/src/types.cpp b/src/types.cpp index 19e8066e..510a69a2 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -581,8 +581,8 @@ namespace Exiv2 { int exifTime(const char* buf, struct tm* tm) { - assert(buf != 0); - assert(tm != 0); + assert(buf); + assert(tm); int rc = 1; int year = 0, mon = 0, mday = 0, hour = 0, min = 0, sec = 0; int scanned = std::sscanf(buf, "%4d:%2d:%2d %2d:%2d:%2d", diff --git a/src/value.cpp b/src/value.cpp index b7edb3b3..d1b05756 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -261,7 +261,7 @@ namespace Exiv2 { if (value_.empty()) return 0; // byteOrder not needed - assert(buf != 0); + assert(buf); return static_cast( value_.copy(reinterpret_cast(buf), value_.size()) ); @@ -465,7 +465,7 @@ namespace Exiv2 { } if (c.empty()) return 0; - assert(buf != 0); + assert(buf); return static_cast(c.copy(reinterpret_cast(buf), c.size())); } @@ -486,7 +486,7 @@ namespace Exiv2 { } c = value_.substr(8); if (charsetId() == unicode) { - const char* from = encoding == nullptr || *encoding == '\0' ? detectCharset(c) : encoding; + const char* from = !encoding || *encoding == '\0' ? detectCharset(c) : encoding; convertStringCharset(c, from, "UTF-8"); } bool bAscii = charsetId() == undefined || charsetId() == ascii ; diff --git a/src/xmp.cpp b/src/xmp.cpp index 816d9de5..c49e24a3 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -290,9 +290,9 @@ namespace Exiv2 { Xmpdatum::Impl::Impl(const Impl& rhs) { - if (rhs.key_.get() != nullptr) + if (rhs.key_) key_ = rhs.key_->clone(); // deep copy - if (rhs.value_.get() != nullptr) + if (rhs.value_) value_ = rhs.value_->clone(); // deep copy } @@ -300,10 +300,10 @@ namespace Exiv2 { { if (this == &rhs) return *this; key_.reset(); - if (rhs.key_.get() != nullptr) + if (rhs.key_) key_ = rhs.key_->clone(); // deep copy value_.reset(); - if (rhs.value_.get() != nullptr) + if (rhs.value_) value_ = rhs.value_->clone(); // deep copy return *this; } @@ -328,40 +328,19 @@ namespace Exiv2 { Xmpdatum::~Xmpdatum() = default; - std::string Xmpdatum::key() const - { - return p_->key_.get() == nullptr ? "" : p_->key_->key(); - } + std::string Xmpdatum::key() const { return p_->key_ ? p_->key_->key() : ""; } - const char* Xmpdatum::familyName() const - { - return p_->key_.get() == nullptr ? "" : p_->key_->familyName(); - } + const char* Xmpdatum::familyName() const { return p_->key_ ? p_->key_->familyName() : ""; } - std::string Xmpdatum::groupName() const - { - return p_->key_.get() == nullptr ? "" : p_->key_->groupName(); - } + std::string Xmpdatum::groupName() const { return p_->key_ ? p_->key_->groupName() : ""; } - std::string Xmpdatum::tagName() const - { - return p_->key_.get() == nullptr ? "" : p_->key_->tagName(); - } + std::string Xmpdatum::tagName() const { return p_->key_ ? p_->key_->tagName() : ""; } - std::string Xmpdatum::tagLabel() const - { - return p_->key_.get() == nullptr ? "" : p_->key_->tagLabel(); - } + std::string Xmpdatum::tagLabel() const { return p_->key_ ? p_->key_->tagLabel() : ""; } - uint16_t Xmpdatum::tag() const - { - return p_->key_.get() == nullptr ? 0 : p_->key_->tag(); - } + uint16_t Xmpdatum::tag() const { return p_->key_ ? p_->key_->tag() : 0; } - TypeId Xmpdatum::typeId() const - { - return p_->value_.get() == nullptr ? invalidTypeId : p_->value_->typeId(); - } + TypeId Xmpdatum::typeId() const { return p_->value_ ? p_->value_->typeId() : invalidTypeId; } const char* Xmpdatum::typeName() const { @@ -373,49 +352,25 @@ namespace Exiv2 { return 0; } - size_t Xmpdatum::count() const - { - return p_->value_.get() == nullptr ? 0 : p_->value_->count(); - } + size_t Xmpdatum::count() const { return p_->value_ ? p_->value_->count() : 0; } - long Xmpdatum::size() const - { - return p_->value_.get() == nullptr ? 0 : static_cast(p_->value_->size()); - } + long Xmpdatum::size() const { return p_->value_ ? static_cast(p_->value_->size()) : 0; } - std::string Xmpdatum::toString() const - { - return p_->value_.get() == nullptr ? "" : p_->value_->toString(); - } + std::string Xmpdatum::toString() const { return p_->value_ ? p_->value_->toString() : ""; } - std::string Xmpdatum::toString(long n) const - { - return p_->value_.get() == nullptr ? "" : p_->value_->toString(n); - } + std::string Xmpdatum::toString(long n) const { return p_->value_ ? p_->value_->toString(n) : ""; } - int64_t Xmpdatum::toInt64(long n) const - { - return p_->value_.get() == nullptr ? -1 : p_->value_->toInt64(n); - } + int64_t Xmpdatum::toInt64(long n) const { return p_->value_ ? p_->value_->toInt64(n) : -1; } - float Xmpdatum::toFloat(long n) const - { - return p_->value_.get() == nullptr ? -1 : p_->value_->toFloat(n); - } + float Xmpdatum::toFloat(long n) const { return p_->value_ ? p_->value_->toFloat(n) : -1; } - Rational Xmpdatum::toRational(long n) const - { - return p_->value_.get() == nullptr ? Rational(-1, 1) : p_->value_->toRational(n); - } + Rational Xmpdatum::toRational(long n) const { return p_->value_ ? p_->value_->toRational(n) : Rational(-1, 1); } - Value::UniquePtr Xmpdatum::getValue() const - { - return p_->value_.get() == nullptr ? nullptr : p_->value_->clone(); - } + Value::UniquePtr Xmpdatum::getValue() const { return p_->value_ ? p_->value_->clone() : nullptr; } const Value& Xmpdatum::value() const { - if (p_->value_.get() == nullptr) + if (!p_->value_) throw Error(kerValueNotSet); return *p_->value_; } @@ -451,9 +406,9 @@ namespace Exiv2 { int Xmpdatum::setValue(const std::string& value) { - if (p_->value_.get() == nullptr) { + if (!p_->value_) { TypeId type = xmpText; - if (nullptr != p_->key_.get()) { + if (p_->key_) { type = XmpProperties::propertyType(*p_->key_.get()); } p_->value_ = Value::create(type); @@ -916,7 +871,7 @@ namespace Exiv2 { if (i.typeId() == langAlt) { // Encode Lang Alt property const auto la = dynamic_cast(&i.value()); - if (la == nullptr) + if (!la) throw Error(kerEncodeLangAltPropertyFailed, i.key()); int idx = 1; @@ -934,7 +889,7 @@ namespace Exiv2 { // Todo: Xmpdatum should have an XmpValue, not a Value const auto val = dynamic_cast(&i.value()); - if (val == nullptr) + if (!val) throw Error(kerInvalidKeyXmpValue, i.key(), i.typeName()); options = xmpArrayOptionBits(val->xmpArrayType()) | xmpArrayOptionBits(val->xmpStruct());