diff --git a/src/basicio.cpp b/src/basicio.cpp index 8ea669e597..eedbb5c628 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -335,7 +335,7 @@ void FileIo::transfer(BasicIo& src) { // Check if the file can be written to, if it already exists if (open("a+b") != 0) { // Remove the (temporary) file - fs::remove(fileIo->path().c_str()); + fs::remove(fileIo->path()); throw Error(ErrorCode::kerFileOpenFailed, path(), "a+b", strError()); } close(); @@ -366,8 +366,8 @@ void FileIo::transfer(BasicIo& src) { pfcn_ReplaceFileA(pf, fileIo->path().c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS, nullptr, nullptr); if (ret == 0) { if (GetLastError() == ERROR_FILE_NOT_FOUND) { - fs::rename(fileIo->path().c_str(), pf); - fs::remove(fileIo->path().c_str()); + fs::rename(fileIo->path(), pf); + fs::remove(fileIo->path()); } else { throw Error(ErrorCode::kerFileRenameFailed, fileIo->path(), pf, strError()); } @@ -376,16 +376,16 @@ void FileIo::transfer(BasicIo& src) { if (fileExists(pf) && ::remove(pf) != 0) { throw Error(ErrorCode::kerCallFailed, pf, strError(), "fs::remove"); } - fs::rename(fileIo->path().c_str(), pf); - fs::remove(fileIo->path().c_str()); + fs::rename(fileIo->path(), pf); + fs::remove(fileIo->path()); } } #else if (fileExists(pf) && fs::remove(pf) != 0) { throw Error(ErrorCode::kerCallFailed, pf, strError(), "fs::remove"); } - fs::rename(fileIo->path().c_str(), pf); - fs::remove(fileIo->path().c_str()); + fs::rename(fileIo->path(), pf); + fs::remove(fileIo->path()); #endif // Check permissions of new file struct stat buf2; @@ -395,13 +395,11 @@ void FileIo::transfer(BasicIo& src) { EXV_WARNING << Error(ErrorCode::kerCallFailed, pf, strError(), "::stat") << "\n"; #endif } - if (statOk && origStMode != buf2.st_mode) { - // Set original file permissions - if (::chmod(pf, origStMode) == -1) { + // Set original file permissions + if (statOk && origStMode != buf2.st_mode && ::chmod(pf, origStMode) == -1) { #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(ErrorCode::kerCallFailed, pf, strError(), "::chmod") << "\n"; + EXV_WARNING << Error(ErrorCode::kerCallFailed, pf, strError(), "::chmod") << "\n"; #endif - } } } } // if (fileIo) @@ -1316,7 +1314,7 @@ byte* RemoteIo::mmap(bool /*isWriteable*/) { size_t blocks = (p_->size_ + blockSize - 1) / blockSize; bigBlock_ = new byte[blocks * blockSize]; for (size_t block = 0; block < blocks; block++) { - void* p = p_->blocksMap_[block].getData(); + auto p = p_->blocksMap_[block].getData(); if (p) { size_t nRead = block == (blocks - 1) ? p_->size_ - nRealData : blockSize; memcpy(bigBlock_ + (block * blockSize), p, nRead); diff --git a/src/bmffimage.cpp b/src/bmffimage.cpp index a6be585a0b..258f750ef4 100644 --- a/src/bmffimage.cpp +++ b/src/bmffimage.cpp @@ -145,11 +145,13 @@ std::string BmffImage::uuidName(Exiv2::DataBuf& uuid) { const char* uuidCano = "\x85\xC0\xB6\x87\x82\xF\x11\xE0\x81\x11\xF4\xCE\x46\x2B\x6A\x48"; const char* uuidXmp = "\xBE\x7A\xCF\xCB\x97\xA9\x42\xE8\x9C\x71\x99\x94\x91\xE3\xAF\xAC"; const char* uuidCanp = "\xEA\xF4\x2B\x5E\x1C\x98\x4B\x88\xB9\xFB\xB7\xDC\x40\x6E\x4D\x16"; - const char* result = uuid.cmpBytes(0, uuidCano, 16) == 0 ? "cano" - : uuid.cmpBytes(0, uuidXmp, 16) == 0 ? "xmp" - : uuid.cmpBytes(0, uuidCanp, 16) == 0 ? "canp" - : ""; - return result; + if (uuid.cmpBytes(0, uuidCano, 16) == 0) + return "cano"; + if (uuid.cmpBytes(0, uuidXmp, 16) == 0) + return "xmp"; + if (uuid.cmpBytes(0, uuidCanp, 16) == 0) + return "canp"; + return ""; } uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintStructureOption option /* = kpsNone */, @@ -345,9 +347,13 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS enforce(data.size() - skip >= (version > 2u ? 4u : 2u), Exiv2::ErrorCode::kerCorruptedMetadata); enforce(data.size() - skip >= step, Exiv2::ErrorCode::kerCorruptedMetadata); uint32_t ID = version > 2 ? data.read_uint32(skip, endian_) : data.read_uint16(skip, endian_); - uint32_t offset = step == 14 || step == 16 ? data.read_uint32(skip + step - 8, endian_) - : step == 18 ? data.read_uint32(skip + 4, endian_) - : 0; + auto offset = [=] { + if (step == 14 || step == 16) + return data.read_uint32(skip + step - 8, endian_); + if (step == 18) + return data.read_uint32(skip + 4, endian_); + return 0u; + }(); uint32_t ldata = data.read_uint32(skip + step - 4, endian_); if (bTrace) { @@ -388,7 +394,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS uint8_t meth = data.read_uint8(skip + 0); uint8_t prec = data.read_uint8(skip + 1); uint8_t approx = data.read_uint8(skip + 2); - std::string colour_type = std::string(data.c_str(), 4); + auto colour_type = std::string(data.c_str(), 4); skip += 4; if (colour_type == "rICC" || colour_type == "prof") { DataBuf profile(data.c_data(skip), data.size() - skip); @@ -554,14 +560,11 @@ void BmffImage::parseCr3Preview(DataBuf& data, std::ostream& out, bool bTrace, u nativePreview.height_ = data.read_uint16(height_offset, endian_); nativePreview.size_ = data.read_uint32(size_offset, endian_); nativePreview.filter_ = ""; - switch (version) { - case 0: - nativePreview.mimeType_ = "image/jpeg"; - break; - default: - nativePreview.mimeType_ = "application/octet-stream"; - break; - } + nativePreview.mimeType_ = [version] { + if (version == 0) + return "image/jpeg"; + return "application/octet-stream"; + }(); nativePreviews_.push_back(nativePreview); if (bTrace) { @@ -639,7 +642,7 @@ void BmffImage::printStructure(std::ostream& out, Exiv2::PrintStructureOption op io_->seek(address, BasicIo::beg); address = boxHandler(out, option, file_end, depth); } - }; break; + } break; } } diff --git a/src/canonmn_int.cpp b/src/canonmn_int.cpp index 9801233f52..f0122340d9 100644 --- a/src/canonmn_int.cpp +++ b/src/canonmn_int.cpp @@ -2582,7 +2582,7 @@ std::ostream& printCsLensFFFF(std::ostream& os, const Value& value, const ExifDa return os << "Canon EF-S 24mm f/2.8 STM"; } } catch (const std::exception&) { - }; + } return EXV_PRINT_TAG(canonCsLensType)(os, value, metadata); } diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 34f86c0922..923cd2c4df 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -127,8 +127,6 @@ const CrwSubDir CrwMap::crwSubDir_[] = { {0x2807, 0x300a}, {0x2804, 0x300a}, {0x300a, 0x0000}, {0x0000, 0xffff}, }; -const char CiffHeader::signature_[] = "HEAPCCDR"; - CiffDirectory::~CiffDirectory() { for (auto&& component : components_) { delete component; @@ -185,7 +183,7 @@ void CiffComponent::doRead(const byte* pData, size_t size, uint32_t start, ByteO DataLocId dl = dataLocation(); - if (dl == valueData) { + if (dl == DataLocId::valueData) { size_ = getULong(pData + start + 2, byteOrder); offset_ = getULong(pData + start + 6, byteOrder); @@ -204,7 +202,7 @@ void CiffComponent::doRead(const byte* pData, size_t size, uint32_t start, ByteO enforce(size_ <= size - offset_, ErrorCode::kerOffsetOutOfRange); } } - if (dl == directoryData) { + if (dl == DataLocId::directoryData) { size_ = 8; offset_ = start + 2; } @@ -316,7 +314,7 @@ size_t CiffEntry::doWrite(Blob& blob, ByteOrder /*byteOrder*/, size_t offset) { } size_t CiffComponent::writeValueData(Blob& blob, size_t offset) { - if (dataLocation() == valueData) { + if (dataLocation() == DataLocId::valueData) { #ifdef EXIV2_DEBUG_MESSAGES std::cout << " Data for tag 0x" << std::hex << tagId() << ", " << std::dec << size_ << " Bytes\n"; #endif @@ -382,7 +380,7 @@ void CiffComponent::writeDirEntry(Blob& blob, ByteOrder byteOrder) const { DataLocId dl = dataLocation(); - if (dl == valueData) { + if (dl == DataLocId::valueData) { us2Data(buf, tag_, byteOrder); append(blob, buf, 2); @@ -393,7 +391,7 @@ void CiffComponent::writeDirEntry(Blob& blob, ByteOrder byteOrder) const { append(blob, buf, 4); } - if (dl == directoryData) { + if (dl == DataLocId::directoryData) { // Only 8 bytes fit in the directory entry us2Data(buf, tag_, byteOrder); @@ -437,43 +435,36 @@ void CiffComponent::setValue(DataBuf&& buf) { storage_ = std::move(buf); pData_ = storage_.c_data(); size_ = storage_.size(); - if (size_ > 8 && dataLocation() == directoryData) { + if (size_ > 8 && dataLocation() == DataLocId::directoryData) { tag_ &= 0x3fff; } } TypeId CiffComponent::typeId(uint16_t tag) { - TypeId ti = invalidTypeId; switch (tag & 0x3800) { case 0x0000: - ti = unsignedByte; - break; + return unsignedByte; case 0x0800: - ti = asciiString; - break; + return asciiString; case 0x1000: - ti = unsignedShort; - break; + return unsignedShort; case 0x1800: - ti = unsignedLong; - break; + return unsignedLong; case 0x2000: - ti = undefined; - break; - case 0x2800: // fallthrough + return undefined; + case 0x2800: case 0x3000: - ti = directory; - break; + return directory; } - return ti; + return invalidTypeId; } // CiffComponent::typeId DataLocId CiffComponent::dataLocation(uint16_t tag) { switch (tag & 0xc000) { case 0x0000: - return valueData; + return DataLocId::valueData; case 0x4000: - return directoryData; + return DataLocId::directoryData; default: throw Error(ErrorCode::kerCorruptedMetadata); } diff --git a/src/crwimage_int.hpp b/src/crwimage_int.hpp index 635a2f542b..eb326bcc01 100644 --- a/src/crwimage_int.hpp +++ b/src/crwimage_int.hpp @@ -35,7 +35,7 @@ using CrwEncodeFct = std::function; //! Type to identify where the data is stored in a directory -enum DataLocId { valueData, directoryData, lastDataLocId }; +enum class DataLocId { valueData, directoryData, lastDataLocId }; // ***************************************************************************** // class definitions @@ -480,7 +480,7 @@ class CiffHeader { private: // DATA - static const char signature_[]; //!< Canon CRW signature "HEAPCCDR" + static constexpr auto signature_ = "HEAPCCDR"; //!< Canon CRW signature std::unique_ptr pRootDir_; //!< Pointer to the root directory ByteOrder byteOrder_ = littleEndian; //!< Applicable byte order diff --git a/src/epsimage.cpp b/src/epsimage.cpp index fe3a68ef93..5e8ea5a3f8 100644 --- a/src/epsimage.cpp +++ b/src/epsimage.cpp @@ -183,7 +183,7 @@ void findXmp(size_t& xmpPos, size_t& xmpSize, const byte* data, size_t startPos, if (data[xmpPos] != '\x00' && data[xmpPos] != '<') continue; for (auto&& xmpTrailer : xmpTrailers) { - auto [trailer, readOnly] = xmpTrailer; + const auto& [trailer, readOnly] = xmpTrailer; if (trailerPos + trailer.size() > size) continue; @@ -524,14 +524,12 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList #endif } } - if (line == "%%EOF" || line == "%%Trailer") { - if (posPageTrailer == posEndEps) { - posPageTrailer = startPos; - implicitPageTrailer = true; + if ((line == "%%EOF" || line == "%%Trailer") && posPageTrailer == posEndEps) { + posPageTrailer = startPos; + implicitPageTrailer = true; #ifdef DEBUG - EXV_DEBUG << "readWriteEpsMetadata: Found implicit PageTrailer at position: " << startPos << "\n"; + EXV_DEBUG << "readWriteEpsMetadata: Found implicit PageTrailer at position: " << startPos << "\n"; #endif - } } // remaining explicit comments if (posEndComments == posEndEps && posLanguageLevel == posEndEps && startsWith(line, "%%LanguageLevel:")) { @@ -702,7 +700,7 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList if (posOtherXmp >= posEndPageSetup) break; bool isRemovableEmbedding = false; - for (auto&& [r, s] : removableEmbeddings) { + for (const auto& [r, s] : removableEmbeddings) { if (r <= posOtherXmp && posOtherXmp < s) { isRemovableEmbedding = true; break; @@ -871,23 +869,20 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList #endif } // update and complement DSC comments - if (pos == posLanguageLevel && posLanguageLevel != posEndEps && !deleteXmp && !useFlexibleEmbedding) { - if (line == "%%LanguageLevel:1" || line == "%%LanguageLevel: 1") { - writeTemp(tempIo, "%%LanguageLevel: 2" + lineEnding); - skipPos = posLineEnd; + if (pos == posLanguageLevel && posLanguageLevel != posEndEps && !deleteXmp && !useFlexibleEmbedding && + (line == "%%LanguageLevel:1" || line == "%%LanguageLevel: 1")) { + writeTemp(tempIo, "%%LanguageLevel: 2" + lineEnding); + skipPos = posLineEnd; #ifdef DEBUG - EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n"; + EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n"; #endif - } } - if (pos == posContainsXmp && posContainsXmp != posEndEps) { - if (line != containsXmpLine) { - writeTemp(tempIo, containsXmpLine + lineEnding); - skipPos = posLineEnd; + if (pos == posContainsXmp && posContainsXmp != posEndEps && line != containsXmpLine) { + writeTemp(tempIo, containsXmpLine + lineEnding); + skipPos = posLineEnd; #ifdef DEBUG - EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n"; + EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n"; #endif - } } if (pos == posExiv2Version && posExiv2Version != posEndEps) { writeTemp(tempIo, "%Exiv2Version: " + versionNumberHexString() + lineEnding); @@ -924,29 +919,23 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList writeTemp(tempIo, "%%EndComments" + lineEnding); } } - if (pos == posPage) { - if (!startsWith(line, "%%Page:")) { - writeTemp(tempIo, "%%Page: 1 1" + lineEnding); - writeTemp(tempIo, "%%EndPageComments" + lineEnding); - } + if (pos == posPage && !startsWith(line, "%%Page:")) { + writeTemp(tempIo, "%%Page: 1 1" + lineEnding); + writeTemp(tempIo, "%%EndPageComments" + lineEnding); } - if (pos == posBeginPageSetup) { - if (line != "%%BeginPageSetup") { - writeTemp(tempIo, "%%BeginPageSetup" + lineEnding); - } + if (pos == posBeginPageSetup && line != "%%BeginPageSetup") { + writeTemp(tempIo, "%%BeginPageSetup" + lineEnding); } - if (useFlexibleEmbedding) { - // insert XMP metadata into existing flexible embedding - if (pos == xmpPos) { - if (fixBeginXmlPacket) { - writeTemp(tempIo, "%begin_xml_packet: " + toString(xmpPacket.size()) + lineEnding); - } - writeTemp(tempIo, xmpPacket); - skipPos += xmpSize; + // insert XMP metadata into existing flexible embedding + if (useFlexibleEmbedding && pos == xmpPos) { + if (fixBeginXmlPacket) { + writeTemp(tempIo, "%begin_xml_packet: " + toString(xmpPacket.size()) + lineEnding); + } + writeTemp(tempIo, xmpPacket); + skipPos += xmpSize; #ifdef DEBUG - EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n"; + EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n"; #endif - } } if (!useFlexibleEmbedding) { // remove preceding embedding(s) @@ -1009,26 +998,21 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList writeTemp(tempIo, "%Exiv2EndXMP" + lineEnding); } } - if (pos == posEndPageSetup) { - if (line != "%%EndPageSetup") { - writeTemp(tempIo, "%%EndPageSetup" + lineEnding); - } + if (pos == posEndPageSetup && line != "%%EndPageSetup") { + writeTemp(tempIo, "%%EndPageSetup" + lineEnding); } - if (!useFlexibleEmbedding) { - if (pos == posPageTrailer && !deleteXmp) { - if (!implicitPageTrailer) { - skipPos = posLineEnd; + if (!useFlexibleEmbedding && pos == posPageTrailer && !deleteXmp) { + if (!implicitPageTrailer) { + skipPos = posLineEnd; #ifdef DEBUG - EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ - << "\n"; + EXV_DEBUG << "readWriteEpsMetadata: Skipping to " << skipPos << " at " << __FILE__ << ":" << __LINE__ << "\n"; #endif - } - writeTemp(tempIo, "%%PageTrailer" + lineEnding); - writeTemp(tempIo, "%Exiv2BeginXMP: After %%PageTrailer" + lineEnding); - writeTemp(tempIo, "[/EMC Exiv2_pdfmark" + lineEnding); - writeTemp(tempIo, "[/NamespacePop Exiv2_pdfmark" + lineEnding); - writeTemp(tempIo, "%Exiv2EndXMP" + lineEnding); } + writeTemp(tempIo, "%%PageTrailer" + lineEnding); + writeTemp(tempIo, "%Exiv2BeginXMP: After %%PageTrailer" + lineEnding); + writeTemp(tempIo, "[/EMC Exiv2_pdfmark" + lineEnding); + writeTemp(tempIo, "[/NamespacePop Exiv2_pdfmark" + lineEnding); + writeTemp(tempIo, "%Exiv2EndXMP" + lineEnding); } // add EOF comment if necessary if (pos == posEndEps && posEof == posEndEps) { @@ -1080,18 +1064,16 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList namespace Exiv2 { EpsImage::EpsImage(BasicIo::UniquePtr io, bool create) : Image(ImageType::eps, mdXmp, std::move(io)) { // LogMsg::setLevel(LogMsg::debug); - if (create) { - if (io_->open() == 0) { + if (create && io_->open() == 0) { #ifdef DEBUG - EXV_DEBUG << "Exiv2::EpsImage:: Creating blank EPS image\n"; + EXV_DEBUG << "Exiv2::EpsImage:: Creating blank EPS image\n"; #endif - IoCloser closer(*io_); - if (io_->write(reinterpret_cast(epsBlank.data()), epsBlank.size()) != epsBlank.size()) { + IoCloser closer(*io_); + if (io_->write(reinterpret_cast(epsBlank.data()), epsBlank.size()) != epsBlank.size()) { #ifndef SUPPRESS_WARNINGS - EXV_WARNING << "Failed to write blank EPS image.\n"; + EXV_WARNING << "Failed to write blank EPS image.\n"; #endif - throw Error(ErrorCode::kerImageWriteFailed); - } + throw Error(ErrorCode::kerImageWriteFailed); } } } diff --git a/src/exif.cpp b/src/exif.cpp index 750eae50c1..ac4b4a269d 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -188,7 +188,7 @@ std::ostream& Exifdatum::write(std::ostream& os, const ExifData* pMetadata) cons // cause a std::out_of_range exception to be thrown. try { fct(os, value(), pMetadata); - } catch (std::out_of_range&) { + } catch (const std::out_of_range&) { os << "Bad value"; #ifdef EXIV2_DEBUG_MESSAGES std::cerr << "Caught std::out_of_range exception in Exifdatum::write().\n"; diff --git a/src/fujimn_int.cpp b/src/fujimn_int.cpp index c77a18a2ad..6b66df4dfb 100644 --- a/src/fujimn_int.cpp +++ b/src/fujimn_int.cpp @@ -78,7 +78,7 @@ constexpr TagDetails fujiContrast[] = {{0, N_("Normal")}, {256, N_("High")}, {76 //! WhiteBalanceFineTune, tag 0x100a std::ostream& printFujiWhiteBalanceFineTune(std::ostream& os, const Value& value, const ExifData*) { if (value.typeId() == signedLong && value.size() == 8) { - auto longValue = static_cast(value); + auto longValue = dynamic_cast(value); if (longValue.toInt64(0) % 20 == 0 && longValue.toInt64(1) % 20 == 0) { auto redShift = longValue.toInt64(0) / 20; auto blueShift = longValue.toInt64(1) / 20; diff --git a/src/image.cpp b/src/image.cpp index 4461d95503..e55ca42a02 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -513,7 +513,7 @@ XmpData& Image::xmpData() { std::string& Image::xmpPacket() { // Serialize the current XMP - if (xmpData_.count() > 0 && !writeXmpFromPacket()) { + if (!xmpData_.empty() && !writeXmpFromPacket()) { XmpParser::encode(xmpPacket_, xmpData_, XmpParser::useCompactFormat | XmpParser::omitAllFormatting); } return xmpPacket_; diff --git a/src/iptc.cpp b/src/iptc.cpp index 8872752d63..258adbc77b 100644 --- a/src/iptc.cpp +++ b/src/iptc.cpp @@ -306,11 +306,8 @@ const char* IptcData::detectCharset() const { auto pos = findKey(IptcKey("Iptc.Envelope.CharacterSet")); if (pos != end()) { const std::string value = pos->toString(); - if (pos->value().ok()) { - if (value == "\033%G") - return "UTF-8"; - // other values are probably not practically relevant - } + if (pos->value().ok() && value == "\033%G") + return "UTF-8"; } bool ascii = true; @@ -320,7 +317,7 @@ const char* IptcData::detectCharset() const { std::string value = pos->toString(); if (pos->value().ok()) { int seqCount = 0; - for (auto&& c : value) { + for (auto c : value) { if (seqCount) { if ((c & 0xc0) != 0x80) { utf8 = false; diff --git a/src/jp2image.cpp b/src/jp2image.cpp index baf76aa9a7..7172d28ebc 100644 --- a/src/jp2image.cpp +++ b/src/jp2image.cpp @@ -802,12 +802,10 @@ void Jp2Image::doWriteMetadata(BasicIo& outIo) { } } - if (!writeXmpFromPacket()) { - if (XmpParser::encode(xmpPacket_, xmpData_) > 1) { + if (!writeXmpFromPacket() && XmpParser::encode(xmpPacket_, xmpData_) > 1) { #ifndef SUPPRESS_WARNINGS - EXV_ERROR << "Failed to encode XMP metadata." << std::endl; + EXV_ERROR << "Failed to encode XMP metadata." << std::endl; #endif - } } if (!xmpPacket_.empty()) { // Update Xmp data to a new UUID box diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index c3f60ab437..0b49dff591 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -251,7 +251,7 @@ void JpegBase::readMetadata() { // Read the beginning of the next segment try { marker = advanceToMarker(ErrorCode::kerFailedToReadImageData); - } catch (Error&) { + } catch (const Error&) { rc = 5; break; } @@ -742,12 +742,11 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) { --search; } } - if (!writeXmpFromPacket()) { - if (XmpParser::encode(xmpPacket_, xmpData_, XmpParser::useCompactFormat | XmpParser::omitAllFormatting) > 1) { + if (!writeXmpFromPacket() && + XmpParser::encode(xmpPacket_, xmpData_, XmpParser::useCompactFormat | XmpParser::omitAllFormatting) > 1) { #ifndef SUPPRESS_WARNINGS - EXV_ERROR << "Failed to encode XMP metadata.\n"; + EXV_ERROR << "Failed to encode XMP metadata.\n"; #endif - } } if (!xmpPacket_.empty()) { std::array tmpBuf; diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index 5ebb01de4e..2cc7fb42d4 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -71,7 +71,7 @@ std::string getExiv2ConfigPath() { currentPath = buffer; } #else - struct passwd* pw = getpwuid(getuid()); + auto pw = getpwuid(getuid()); currentPath = std::string(pw ? pw->pw_dir : ""); #endif return (currentPath / inifile).string(); @@ -815,9 +815,8 @@ TiffComponent* newSony2Mn2(uint16_t tag, IfdId group, IfdId mnGroup) { TiffComponent* newCasioMn(uint16_t tag, IfdId group, IfdId /* mnGroup*/, const byte* pData, size_t size, ByteOrder /* byteOrder */) { - if (size > 6 && std::string(reinterpret_cast(pData), 6) == std::string("QVC\0\0\0", 6)) { + if (size > 6 && std::string(reinterpret_cast(pData), 6) == std::string("QVC\0\0\0", 6)) return newCasio2Mn2(tag, group, IfdId::casio2Id); - }; // Require at least an IFD with 1 entry, but not necessarily a next pointer if (size < 14) return nullptr; diff --git a/src/olympusmn_int.cpp b/src/olympusmn_int.cpp index d40377f573..c0adceb9fe 100644 --- a/src/olympusmn_int.cpp +++ b/src/olympusmn_int.cpp @@ -1188,14 +1188,10 @@ std::ostream& OlympusMakerNote::print0x1015(std::ostream& os, const Value& value auto l0 = value.toInt64(0); auto l1 = value.toInt64(1); if (l0 == 1) { - switch (l1) { - case 0: - os << _("Auto"); - break; - default: - os << _("Auto") << " (" << l1 << ")"; - break; - } + if (l1 == 0) + os << _("Auto"); + else + os << _("Auto") << " (" << l1 << ")"; } else if (l0 == 2) { switch (l1) { case 2: @@ -1224,17 +1220,12 @@ std::ostream& OlympusMakerNote::print0x1015(std::ostream& os, const Value& value break; } } else if (l0 == 3) { - switch (l1) { - case 0: - os << _("One-touch"); - break; - default: - os << value; - break; - } - } else { + if (l1 == 0) + os << _("One-touch"); + else + os << value; + } else return os << value; - } } else { return os << value; } @@ -1380,7 +1371,7 @@ std::ostream& OlympusMakerNote::print0x0201(std::ostream& os, const Value& value auto v2 = static_cast(value.toInt64(2)); auto v3 = static_cast(value.toInt64(3)); - for (auto&& type : lensTypes) { + for (const auto& type : lensTypes) { if (type.val[0] == v0 && type.val[1] == v2 && type.val[2] == v3) { return os << type.label; } @@ -1423,7 +1414,7 @@ std::ostream& OlympusMakerNote::printEq0x0301(std::ostream& os, const Value& val auto v0 = static_cast(value.toInt64(0)); auto v2 = static_cast(value.toInt64(2)); - for (auto&& model : extenderModels) { + for (const auto& model : extenderModels) { if (model.val[0] == v0 && model.val[1] == v2) { return os << model.label; } diff --git a/src/orfimage.cpp b/src/orfimage.cpp index d6d4cdcf61..d812310a4d 100644 --- a/src/orfimage.cpp +++ b/src/orfimage.cpp @@ -56,12 +56,11 @@ void OrfImage::printStructure(std::ostream& out, PrintStructureOption option, si if (io_->open() != 0) throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError()); // Ensure that this is the correct image type - if (imageType() == ImageType::none) - if (!isOrfType(*io_, false)) { - if (io_->error() || io_->eof()) - throw Error(ErrorCode::kerFailedToReadImageData); - throw Error(ErrorCode::kerNotAJpeg); - } + if (imageType() == ImageType::none && !isOrfType(*io_, false)) { + if (io_->error() || io_->eof()) + throw Error(ErrorCode::kerFailedToReadImageData); + throw Error(ErrorCode::kerNotAJpeg); + } io_->seek(0, BasicIo::beg); @@ -95,15 +94,13 @@ void OrfImage::writeMetadata() { byte* pData = nullptr; size_t size = 0; IoCloser closer(*io_); - if (io_->open() == 0) { - // Ensure that this is the correct image type - if (isOrfType(*io_, false)) { - pData = io_->mmap(true); - size = io_->size(); - OrfHeader orfHeader; - if (0 == orfHeader.read(pData, 8)) { - bo = orfHeader.byteOrder(); - } + // Ensure that this is the correct image type + if (io_->open() == 0 && isOrfType(*io_, false)) { + pData = io_->mmap(true); + size = io_->size(); + OrfHeader orfHeader; + if (0 == orfHeader.read(pData, 8)) { + bo = orfHeader.byteOrder(); } } if (bo == invalidByteOrder) { diff --git a/src/panasonicmn_int.cpp b/src/panasonicmn_int.cpp index 16482c6bcf..6df3d09e33 100644 --- a/src/panasonicmn_int.cpp +++ b/src/panasonicmn_int.cpp @@ -550,17 +550,16 @@ std::ostream& PanasonicMakerNote::print0x0033(std::ostream& os, const Value& val os << N_("not set"); } else { os << value; - }; + } return os; } // PanasonicMakerNote::print0x0033 // Travel days std::ostream& PanasonicMakerNote::print0x0036(std::ostream& os, const Value& value, const ExifData*) { - if (value.toInt64() == 65535) { + if (value.toInt64() == 65535) os << N_("not set"); - } else { + else os << value; - }; return os; } // PanasonicMakerNote::print0x0036 @@ -576,7 +575,7 @@ std::ostream& PanasonicMakerNote::print0x003c(std::ostream& os, const Value& val default: os << value; break; - }; + } return os; } // PanasonicMakerNote::print0x003c @@ -596,14 +595,10 @@ std::ostream& PanasonicMakerNote::printPanasonicText(std::ostream& os, const Val // Manometer Pressure std::ostream& PanasonicMakerNote::printPressure(std::ostream& os, const Value& value, const ExifData*) { - switch (value.toInt64()) { - case 65535: - os << N_("infinite"); - break; - default: - os << value << N_(" hPa"); - break; - }; + if (value.toInt64() == 65535) + os << N_("infinite"); + else + os << value << N_(" hPa"); return os; } // PanasonicMakerNote::printPressure diff --git a/src/pgfimage.cpp b/src/pgfimage.cpp index dcac597396..4ea8a292a0 100644 --- a/src/pgfimage.cpp +++ b/src/pgfimage.cpp @@ -51,17 +51,15 @@ static uint32_t byteSwap_(Exiv2::DataBuf& buf, size_t offset, bool bSwap) { PgfImage::PgfImage(BasicIo::UniquePtr io, bool create) : Image(ImageType::pgf, mdExif | mdIptc | mdXmp | mdComment, std::move(io)), bSwap_(isBigEndianPlatform()) { - if (create) { - if (io_->open() == 0) { + if (create && io_->open() == 0) { #ifdef EXIV2_DEBUG_MESSAGES - std::cerr << "Exiv2::PgfImage:: Creating PGF image to memory\n"; + std::cerr << "Exiv2::PgfImage:: Creating PGF image to memory\n"; #endif - IoCloser closer(*io_); - if (io_->write(pgfBlank, sizeof(pgfBlank)) != sizeof(pgfBlank)) { + IoCloser closer(*io_); + if (io_->write(pgfBlank, sizeof(pgfBlank)) != sizeof(pgfBlank)) { #ifdef EXIV2_DEBUG_MESSAGES - std::cerr << "Exiv2::PgfImage:: Failed to create PGF image on memory\n"; + std::cerr << "Exiv2::PgfImage:: Failed to create PGF image on memory\n"; #endif - } } } } // PgfImage::PgfImage diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp index 05679947f0..0bf19ece07 100644 --- a/src/pngchunk_int.cpp +++ b/src/pngchunk_int.cpp @@ -288,23 +288,21 @@ void PngChunk::parseChunkContent(Image* pImage, const byte* key, size_t keySize, // We look if an Adobe XMP string exist. - if (keySize >= 17 && memcmp("XML:com.adobe.xmp", key, 17) == 0 && pImage->xmpData().empty()) { - if (!arr.empty()) { - std::string& xmpPacket = pImage->xmpPacket(); - xmpPacket.assign(arr.c_str(), arr.size()); - std::string::size_type idx = xmpPacket.find_first_of('<'); - if (idx != std::string::npos && idx > 0) { + if (keySize >= 17 && memcmp("XML:com.adobe.xmp", key, 17) == 0 && pImage->xmpData().empty() && !arr.empty()) { + std::string& xmpPacket = pImage->xmpPacket(); + xmpPacket.assign(arr.c_str(), arr.size()); + std::string::size_type idx = xmpPacket.find_first_of('<'); + if (idx != std::string::npos && idx > 0) { #ifndef SUPPRESS_WARNINGS - EXV_WARNING << "Removing " << idx << " characters " - << "from the beginning of the XMP packet\n"; + EXV_WARNING << "Removing " << idx << " characters " + << "from the beginning of the XMP packet\n"; #endif - xmpPacket = xmpPacket.substr(idx); - } - if (XmpParser::decode(pImage->xmpData(), xmpPacket)) { + xmpPacket = xmpPacket.substr(idx); + } + if (XmpParser::decode(pImage->xmpData(), xmpPacket)) { #ifndef SUPPRESS_WARNINGS - EXV_WARNING << "Failed to decode XMP metadata.\n"; + EXV_WARNING << "Failed to decode XMP metadata.\n"; #endif - } } } @@ -593,8 +591,8 @@ std::string PngChunk::writeRawProfile(const std::string& profileData, const char for (std::string::size_type i = 0; i < profileData.size(); ++i) { if (i % 36 == 0) oss << '\n'; - oss << hex[((*sp >> 4) & 0x0fU)]; - oss << hex[((*sp++) & 0x0fU)]; + oss << hex[*sp >> 4 & 0x0fU]; + oss << hex[*sp++ & 0x0fU]; } oss << '\n'; return oss.str(); diff --git a/src/pngimage.cpp b/src/pngimage.cpp index 1facf7c3f5..f9a6bbd8ab 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -53,17 +53,15 @@ using namespace Internal; PngImage::PngImage(BasicIo::UniquePtr io, bool create) : Image(ImageType::png, mdExif | mdIptc | mdXmp | mdComment, std::move(io)) { - if (create) { - if (io_->open() == 0) { + if (create && io_->open() == 0) { #ifdef EXIV2_DEBUG_MESSAGES - std::cerr << "Exiv2::PngImage:: Creating PNG image to memory\n"; + std::cerr << "Exiv2::PngImage:: Creating PNG image to memory\n"; #endif - IoCloser closer(*io_); - if (io_->write(pngBlank, sizeof(pngBlank)) != sizeof(pngBlank)) { + IoCloser closer(*io_); + if (io_->write(pngBlank, sizeof(pngBlank)) != sizeof(pngBlank)) { #ifdef EXIV2_DEBUG_MESSAGES - std::cerr << "Exiv2::PngImage:: Failed to create PNG image on memory\n"; + std::cerr << "Exiv2::PngImage:: Failed to create PNG image on memory\n"; #endif - } } } } @@ -572,7 +570,7 @@ void PngImage::doWriteMetadata(BasicIo& outIo) { } } - if (exifData_.count() > 0) { + if (!exifData_.empty()) { // Update Exif data to a new PNG chunk Blob blob; ExifParser::encode(blob, littleEndian, exifData_); @@ -587,7 +585,7 @@ void PngImage::doWriteMetadata(BasicIo& outIo) { } } - if (iptcData_.count() > 0) { + if (!iptcData_.empty()) { // Update IPTC data to a new PNG chunk DataBuf newPsData = Photoshop::setIptcIrb(nullptr, 0, iptcData_); if (!newPsData.empty()) { @@ -630,12 +628,10 @@ void PngImage::doWriteMetadata(BasicIo& outIo) { } } - if (!writeXmpFromPacket()) { - if (XmpParser::encode(xmpPacket_, xmpData_) > 1) { + if (!writeXmpFromPacket() && XmpParser::encode(xmpPacket_, xmpData_) > 1) { #ifndef SUPPRESS_WARNINGS - EXV_ERROR << "Failed to encode XMP metadata.\n"; + EXV_ERROR << "Failed to encode XMP metadata.\n"; #endif - } } if (!xmpPacket_.empty()) { // Update XMP data to a new PNG chunk diff --git a/src/properties.cpp b/src/properties.cpp index 45e45a0c56..8acfdc3baa 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -4912,18 +4912,15 @@ XmpNsInfo::Prefix::Prefix(std::string prefix) : prefix_(std::move(prefix)) { } bool XmpNsInfo::operator==(const XmpNsInfo::Ns& ns) const { - std::string n(ns_); - return n == ns.ns_; + return ns_ == ns.ns_; } bool XmpNsInfo::operator==(const XmpNsInfo::Prefix& prefix) const { - std::string p(prefix_); - return p == prefix.prefix_; + return prefix_ == prefix.prefix_; } bool XmpPropertyInfo::operator==(const std::string& name) const { - std::string n(name_); - return n == name; + return name_ == name; } XmpProperties::NsRegistry XmpProperties::nsRegistry_; @@ -4931,20 +4928,20 @@ std::mutex XmpProperties::mutex_; /// \todo not used internally. At least we should test it const XmpNsInfo* XmpProperties::lookupNsRegistry(const XmpNsInfo::Prefix& prefix) { - auto scoped_read_lock = std::scoped_lock(mutex_); + auto scopedReadLock = std::scoped_lock(mutex_); return lookupNsRegistryUnsafe(prefix); } const XmpNsInfo* XmpProperties::lookupNsRegistryUnsafe(const XmpNsInfo::Prefix& prefix) { - for (auto&& ns : nsRegistry_) { - if (ns.second == prefix) - return &(ns.second); + for (const auto& [_, p] : nsRegistry_) { + if (p == prefix) + return &p; } return nullptr; } void XmpProperties::registerNs(const std::string& ns, const std::string& prefix) { - auto scoped_write_lock = std::scoped_lock(mutex_); + auto scopedWriteLock = std::scoped_lock(mutex_); std::string ns2 = ns; if (ns2.substr(ns2.size() - 1, 1) != "/" && ns2.substr(ns2.size() - 1, 1) != "#") ns2 += "/"; diff --git a/src/psdimage.cpp b/src/psdimage.cpp index da62a70f81..9e09b82eb0 100644 --- a/src/psdimage.cpp +++ b/src/psdimage.cpp @@ -584,7 +584,7 @@ uint32_t PsdImage::writeExifData(const ExifData& exifData, BasicIo& out) { uint32_t resLength = 0; byte buf[8]; - if (exifData.count() > 0) { + if (!exifData.empty()) { Blob blob; ByteOrder bo = byteOrder(); if (bo == invalidByteOrder) { @@ -634,12 +634,10 @@ uint32_t PsdImage::writeXmpData(const XmpData& xmpData, BasicIo& out) const { std::cerr << "writeXmpFromPacket(): " << writeXmpFromPacket() << "\n"; #endif // writeXmpFromPacket(true); - if (!writeXmpFromPacket()) { - if (XmpParser::encode(xmpPacket, xmpData) > 1) { + if (!writeXmpFromPacket() && XmpParser::encode(xmpPacket, xmpData) > 1) { #ifndef SUPPRESS_WARNINGS - EXV_ERROR << "Failed to encode XMP metadata.\n"; + EXV_ERROR << "Failed to encode XMP metadata.\n"; #endif - } } if (!xmpPacket.empty()) { diff --git a/src/rw2image.cpp b/src/rw2image.cpp index 54bd4fa803..696fcf9949 100644 --- a/src/rw2image.cpp +++ b/src/rw2image.cpp @@ -66,12 +66,11 @@ void Rw2Image::printStructure(std::ostream& out, PrintStructureOption option, si if (io_->open() != 0) throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError()); // Ensure that this is the correct image type - if (imageType() == ImageType::none) - if (!isRw2Type(*io_, false)) { - if (io_->error() || io_->eof()) - throw Error(ErrorCode::kerFailedToReadImageData); - throw Error(ErrorCode::kerNotAJpeg); - } + if (imageType() == ImageType::none && !isRw2Type(*io_, false)) { + if (io_->error() || io_->eof()) + throw Error(ErrorCode::kerFailedToReadImageData); + throw Error(ErrorCode::kerNotAJpeg); + } io_->seek(0, BasicIo::beg); @@ -121,7 +120,7 @@ void Rw2Image::readMetadata() { ExifData& prevData = image->exifData(); if (!prevData.empty()) { // Filter duplicate tags - for (auto&& pos : exifData_) { + for (const auto& pos : exifData_) { if (pos.ifdId() == IfdId::panaRawId) continue; auto dup = prevData.findKey(ExifKey(pos.key())); @@ -176,7 +175,7 @@ void Rw2Image::readMetadata() { } // Add the remaining tags - for (auto&& pos : prevData) { + for (const auto& pos : prevData) { exifData_.add(pos); } diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index 8335f1ae8e..f9ac8f0424 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -50,10 +50,6 @@ Exiv2::ByteOrder stringToByteOrder(const std::string& val) { // ***************************************************************************** // class member definitions namespace Exiv2::Internal { -TiffVisitor::TiffVisitor() { - go_.fill(true); -} - void TiffVisitor::setGo(GoEvent event, bool go) { go_[event] = go; } diff --git a/src/tiffvisitor_int.hpp b/src/tiffvisitor_int.hpp index ec0fb9bbed..c5f8c0e130 100644 --- a/src/tiffvisitor_int.hpp +++ b/src/tiffvisitor_int.hpp @@ -48,14 +48,12 @@ class TiffVisitor { }; private: - static const int events_ = 2; //!< The number of stop/go flags. - std::array go_{}; //!< Array of stop/go flags. See setGo(). + static const int events_ = 2; //!< The number of stop/go flags. + std::array go_{true, true}; //!< Array of stop/go flags. See setGo(). public: //! @name Creators //@{ - //! Default constructor. Initialises all stop/go flags to true. - TiffVisitor(); //! Virtual destructor virtual ~TiffVisitor() = default; //@} diff --git a/src/value.cpp b/src/value.cpp index 7d445753c4..05b5f68872 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -651,7 +651,7 @@ int LangAltValue::read(const std::string& buf) { std::string b = buf; std::string lang = "x-default"; if (buf.length() > 5 && buf.substr(0, 5) == "lang=") { - static const char* ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + static constexpr auto ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; const std::string::size_type pos = buf.find_first_of(' '); if (pos == std::string::npos) { @@ -677,7 +677,7 @@ int LangAltValue::read(const std::string& buf) { // Check language is in the correct format (see https://www.ietf.org/rfc/rfc3066.txt) std::string::size_type charPos = lang.find_first_not_of(ALPHA); if (charPos != std::string::npos) { - static const char* ALPHA_NUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + static constexpr auto ALPHA_NUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; if (lang.at(charPos) != '-' || lang.find_first_not_of(ALPHA_NUM, charPos + 1) != std::string::npos) throw Error(ErrorCode::kerInvalidLangAltValue, buf); } diff --git a/src/webpimage.cpp b/src/webpimage.cpp index 3ed3b4220c..ff595c23c0 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -69,7 +69,6 @@ namespace { // ***************************************************************************** // class member definitions namespace Exiv2 { -using namespace Exiv2::Internal; WebPImage::WebPImage(BasicIo::UniquePtr io) : Image(ImageType::webp, mdNone, std::move(io)) { } // WebPImage::WebPImage