From 97ad113ca43257f56f1474ac390c0de81c1ef282 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 10 Oct 2025 13:01:20 -0700 Subject: [PATCH 1/5] clang: fix -Wdocumentation warnings Signed-off-by: Rosen Penev --- include/exiv2/bmpimage.hpp | 4 ++++ include/exiv2/matroskavideo.hpp | 2 +- include/exiv2/quicktimevideo.hpp | 2 +- include/exiv2/slice.hpp | 4 ++-- src/image_int.hpp | 4 ++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/exiv2/bmpimage.hpp b/include/exiv2/bmpimage.hpp index a607f94afd..6ba2e205bd 100644 --- a/include/exiv2/bmpimage.hpp +++ b/include/exiv2/bmpimage.hpp @@ -48,15 +48,19 @@ class EXIV2API BmpImage : public Image { void readMetadata() override; /// @throws Error(ErrorCode::kerWritingImageFormatUnsupported). + /// Always void writeMetadata() override; /// @throws Error(ErrorCode::kerInvalidSettingForImage) + /// Always void setExifData(const ExifData& exifData) override; /// @throws Error(ErrorCode::kerInvalidSettingForImage) + /// Always void setIptcData(const IptcData& iptcData) override; /// @throws Error(ErrorCode::kerInvalidSettingForImage) + /// Always void setComment(const std::string&) override; //@} diff --git a/include/exiv2/matroskavideo.hpp b/include/exiv2/matroskavideo.hpp index 1101bafa80..187579765a 100644 --- a/include/exiv2/matroskavideo.hpp +++ b/include/exiv2/matroskavideo.hpp @@ -149,11 +149,11 @@ class EXIV2API MatroskaVideo : public Image { @param size Size of \em buf. */ + void decodeDateTags(const Internal::MatroskaTag* tag, const byte* buf, size_t size); void decodeInternalTags(const Internal::MatroskaTag* tag, const byte* buf); void decodeStringTags(const Internal::MatroskaTag* tag, const byte* buf); void decodeIntegerTags(const Internal::MatroskaTag* tag, const byte* buf); void decodeBooleanTags(const Internal::MatroskaTag* tag, const byte* buf); - void decodeDateTags(const Internal::MatroskaTag* tag, const byte* buf, size_t size); void decodeFloatTags(const Internal::MatroskaTag* tag, const byte* buf); private: diff --git a/include/exiv2/quicktimevideo.hpp b/include/exiv2/quicktimevideo.hpp index fcd798aa81..dfd8ad1d39 100644 --- a/include/exiv2/quicktimevideo.hpp +++ b/include/exiv2/quicktimevideo.hpp @@ -137,7 +137,7 @@ class EXIV2API QuickTimeVideo : public Image { /*! @brief Interpret User Data Tag, and save it in the respective XMP container. - @param size Size of the data block used to store Tag Information. + @param outer_size Size of the data block used to store Tag Information. */ void userDataDecoder(size_t outer_size, size_t recursion_depth); /*! diff --git a/include/exiv2/slice.hpp b/include/exiv2/slice.hpp index 91c81b5230..cffc399e0c 100644 --- a/include/exiv2/slice.hpp +++ b/include/exiv2/slice.hpp @@ -326,7 +326,7 @@ struct PtrSliceStorage { * Obtain a reference to the element with the given `index` in the * array. * - * @throw nothing + * @note Does not throw */ [[nodiscard]] auto& unsafeAt(size_t index) noexcept { return data_[index]; @@ -340,7 +340,7 @@ struct PtrSliceStorage { * Obtain an iterator (=pointer) at the position of the element with * the given index in the container. * - * @throw nothing + * @note Does not throw */ [[nodiscard]] auto unsafeGetIteratorAt(size_t index) noexcept { return data_ + index; diff --git a/src/image_int.hpp b/src/image_int.hpp index d409537aef..14cb402f90 100644 --- a/src/image_int.hpp +++ b/src/image_int.hpp @@ -46,10 +46,10 @@ struct binaryToStringHelper; * @brief Actual implementation of the output algorithm described in @ref * binaryToString * - * @throws nothing + * @note Does not throw */ template -std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper& binToStr) { +std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper& binToStr) noexcept { for (size_t i = 0; i < binToStr.buf_.size(); ++i) { auto c = static_cast(binToStr.buf_.at(i)); if (c != 0 || i != binToStr.buf_.size() - 1) { From b6805fb225c4780009d6a6de97e3ad953414c834 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 10 Oct 2025 16:59:49 -0700 Subject: [PATCH 2/5] small upper/lower improvement Use for each loop instead of transform. The latter is overkill. Also use string_view. Lighterweight. Signed-off-by: Rosen Penev --- src/utils.cpp | 17 ++++++++++------- src/utils.hpp | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index 8eb0a1d6f5..a84dda4278 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,20 +1,23 @@ #include "utils.hpp" -#include #include #include namespace Exiv2::Internal { -std::string upper(const std::string& str) { - std::string result = str; - std::transform(str.begin(), str.end(), result.begin(), [](int c) { return static_cast(toupper(c)); }); +std::string upper(std::string_view str) { + std::string result; + result.reserve(str.size()); + for (auto c : str) + result.push_back(std::toupper(static_cast(c))); return result; } -std::string lower(const std::string& a) { - std::string b = a; - std::transform(a.begin(), a.end(), b.begin(), [](int c) { return static_cast(tolower(c)); }); +std::string lower(std::string_view a) { + std::string b; + b.reserve(a.size()); + for (auto c : a) + b.push_back(std::tolower(static_cast(c))); return b; } diff --git a/src/utils.hpp b/src/utils.hpp index 1284fb4137..02a41ac709 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -16,10 +16,10 @@ constexpr bool contains(std::string_view s, T c) { } /// @brief Returns the uppercase version of \b str -std::string upper(const std::string& str); +std::string upper(std::string_view str); /// @brief Returns the lowercase version of \b str -std::string lower(const std::string& a); +std::string lower(std::string_view a); } // namespace Exiv2::Internal From f93bcba3000cfb932581d19f9afdcdda149d28f3 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 11 Oct 2025 13:14:32 -0700 Subject: [PATCH 3/5] use auto return type Signed-off-by: Rosen Penev --- src/image_int.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/image_int.hpp b/src/image_int.hpp index 14cb402f90..1cbd06d1f3 100644 --- a/src/image_int.hpp +++ b/src/image_int.hpp @@ -95,7 +95,7 @@ struct binaryToStringHelper { * the stream throws neither. */ template -constexpr binaryToStringHelper binaryToString(Slice&& sl) noexcept { +constexpr auto binaryToString(Slice&& sl) noexcept { return binaryToStringHelper(std::move(sl)); } From efe7770bf3d8310a3adf2d9e948f05cc14dc6e29 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 12 Oct 2025 17:21:09 -0700 Subject: [PATCH 4/5] coverity: add missing fmtflags Needed when using ostream modifiers. Signed-off-by: Rosen Penev --- app/actions.cpp | 37 +++++++++++++++++++++++++++---------- src/pentaxmn_int.cpp | 2 ++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/app/actions.cpp b/app/actions.cpp index ca69c047c2..b597b60439 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -447,13 +447,21 @@ bool Print::printMetadatum(const Exiv2::Metadatum& md, const Exiv2::Image* pImag bool const manyFiles = Params::instance().files_.size() > 1; if (manyFiles) { - std::cout << std::setfill(' ') << std::left << std::setw(20) << path_ << " "; + std::ostringstream os; + std::ios::fmtflags f(os.flags()); + os << std::setfill(' ') << std::left << std::setw(20) << path_ << " "; + binaryOutput(os); + os.flags(f); } bool first = true; if (Params::instance().printItems_ & Params::prTag) { first = false; - std::cout << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << md.tag(); + std::ostringstream os; + std::ios::fmtflags f(os.flags()); + os << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << md.tag(); + binaryOutput(os); + os.flags(f); } if (Params::instance().printItems_ & Params::prSet) { if (!first) @@ -522,6 +530,7 @@ bool Print::printMetadatum(const Exiv2::Metadatum& md, const Exiv2::Image* pImag std::cout << " "; first = false; std::ostringstream os; + std::ios::fmtflags f(os.flags()); // #1114 - show negative values for SByte if (md.typeId() == Exiv2::signedByte) { for (size_t c = 0; c < md.value().count(); c++) { @@ -532,14 +541,17 @@ bool Print::printMetadatum(const Exiv2::Metadatum& md, const Exiv2::Image* pImag os << std::dec << md.value(); } binaryOutput(os); + os.flags(f); } if (Params::instance().printItems_ & Params::prTrans) { if (!first) std::cout << " "; first = false; std::ostringstream os; + std::ios::fmtflags f(os.flags()); os << std::dec << md.print(&pImage->exifData()); binaryOutput(os); + os.flags(f); } if (Params::instance().printItems_ & Params::prHex) { if (!first) @@ -580,17 +592,22 @@ int Print::printPreviewList() { bool const manyFiles = Params::instance().files_.size() > 1; int cnt = 0; Exiv2::PreviewManager pm(*image); + std::ostringstream os; + std::ios::fmtflags f(os.flags()); Exiv2::PreviewPropertiesList list = pm.getPreviewProperties(); for (const auto& pos : list) { - if (manyFiles) { - std::cout << std::setfill(' ') << std::left << std::setw(20) << path_ << " "; - } - std::cout << _("Preview") << " " << ++cnt << ": " << pos.mimeType_ << ", "; - if (pos.width_ != 0 && pos.height_ != 0) { - std::cout << pos.width_ << "x" << pos.height_ << " " << _("pixels") << ", "; - } - std::cout << pos.size_ << " " << _("bytes") << "\n"; + if (manyFiles) + os << std::setfill(' ') << std::left << std::setw(20) << path_ << " "; + + os << _("Preview") << " " << ++cnt << ": " << pos.mimeType_ << ", "; + + if (pos.width_ != 0 && pos.height_ != 0) + os << pos.width_ << "x" << pos.height_ << " " << _("pixels") << ", "; + + os << pos.size_ << " " << _("bytes") << "\n"; } + binaryOutput(os); + os.flags(f); return 0; } // Print::printPreviewList diff --git a/src/pentaxmn_int.cpp b/src/pentaxmn_int.cpp index 6011854d62..2cf10178d1 100644 --- a/src/pentaxmn_int.cpp +++ b/src/pentaxmn_int.cpp @@ -996,6 +996,7 @@ std::ostream& PentaxMakerNote::printFlashCompensation(std::ostream& os, const Va } std::ostream& PentaxMakerNote::printBracketing(std::ostream& os, const Value& value, const ExifData*) { + std::ios::fmtflags f(os.flags()); if (auto l0 = value.toUint32(0); l0 < 10) { os << std::setprecision(2) << static_cast(l0) / 3 << " EV"; } else { @@ -1034,6 +1035,7 @@ std::ostream& PentaxMakerNote::printBracketing(std::ostream& os, const Value& va } os << ")"; } + os.flags(f); return os; } From b5bdc79c6e5881f272ccb8b5bcf0257bdc61431a Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Thu, 16 Oct 2025 22:26:35 -0700 Subject: [PATCH 5/5] cppcheck: const additions Signed-off-by: Rosen Penev --- include/exiv2/cr2image.hpp | 2 +- include/exiv2/image.hpp | 2 +- include/exiv2/jpgimage.hpp | 2 +- include/exiv2/orfimage.hpp | 2 +- include/exiv2/preview.hpp | 4 ++-- include/exiv2/tiffimage.hpp | 2 +- src/cr2image.cpp | 4 ++-- src/crwimage_int.cpp | 2 +- src/datasets.cpp | 2 +- src/image.cpp | 2 +- src/orfimage.cpp | 4 ++-- src/preview.cpp | 4 ++-- src/tiffcomposite_int.cpp | 2 +- src/tiffimage.cpp | 4 ++-- 14 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/exiv2/cr2image.hpp b/include/exiv2/cr2image.hpp index 4a3151dd88..7cb7fd00f2 100644 --- a/include/exiv2/cr2image.hpp +++ b/include/exiv2/cr2image.hpp @@ -90,7 +90,7 @@ class EXIV2API Cr2Parser { See TiffParser::encode(). */ static WriteMethod encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData, - IptcData& iptcData, XmpData& xmpData); + const IptcData& iptcData, const XmpData& xmpData); }; // class Cr2Parser diff --git a/include/exiv2/image.hpp b/include/exiv2/image.hpp index 00bfe40c6c..39a8a11e12 100644 --- a/include/exiv2/image.hpp +++ b/include/exiv2/image.hpp @@ -205,7 +205,7 @@ class EXIV2API Image { /*! @brief Throw an exception if the size at the beginning of the iccProfile isn't correct. */ - void checkIccProfile(); + void checkIccProfile() const; /*! @brief Erase iccProfile. the profile is not removed from the actual image until the writeMetadata() method is called. diff --git a/include/exiv2/jpgimage.hpp b/include/exiv2/jpgimage.hpp index 3278e6f4bb..76f1e4ef84 100644 --- a/include/exiv2/jpgimage.hpp +++ b/include/exiv2/jpgimage.hpp @@ -165,7 +165,7 @@ class EXIV2API JpegImage : public JpegBase { /*! @brief Get the encoding process of the JPEG Image derived from the Start of Frame (SOF) markers */ - [[nodiscard]] std::string encodingProcess() const { + [[nodiscard]] const std::string& encodingProcess() const { return sof_encoding_process_; } //@} diff --git a/include/exiv2/orfimage.hpp b/include/exiv2/orfimage.hpp index 9a4f02ba16..d81d15042e 100644 --- a/include/exiv2/orfimage.hpp +++ b/include/exiv2/orfimage.hpp @@ -79,7 +79,7 @@ class EXIV2API OrfParser { See TiffParser::encode(). */ static WriteMethod encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData, - IptcData& iptcData, XmpData& xmpData); + const IptcData& iptcData, const XmpData& xmpData); }; // class OrfParser // ***************************************************************************** diff --git a/include/exiv2/preview.hpp b/include/exiv2/preview.hpp index c9c0b9c79e..2f63599a89 100644 --- a/include/exiv2/preview.hpp +++ b/include/exiv2/preview.hpp @@ -87,12 +87,12 @@ class EXIV2API PreviewImage { @brief Return the MIME type of the preview image, usually either \c "image/tiff" or \c "image/jpeg". */ - [[nodiscard]] std::string mimeType() const; + [[nodiscard]] const std::string& mimeType() const; /*! @brief Return the file extension for the format of the preview image (".tif" or ".jpg"). */ - [[nodiscard]] std::string extension() const; + [[nodiscard]] const std::string& extension() const; /*! @brief Return the width of the preview image in pixels. */ diff --git a/include/exiv2/tiffimage.hpp b/include/exiv2/tiffimage.hpp index 9d11b20981..a49db6a0f9 100644 --- a/include/exiv2/tiffimage.hpp +++ b/include/exiv2/tiffimage.hpp @@ -138,7 +138,7 @@ class EXIV2API TiffParser { @return Write method used. */ static WriteMethod encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData, - IptcData& iptcData, XmpData& xmpData); + const IptcData& iptcData, const XmpData& xmpData); }; // class TiffParser diff --git a/src/cr2image.cpp b/src/cr2image.cpp index 091603d069..7b3261b957 100644 --- a/src/cr2image.cpp +++ b/src/cr2image.cpp @@ -78,7 +78,7 @@ void Cr2Image::writeMetadata() { std::cerr << "Writing CR2 file " << io_->path() << "\n"; #endif ByteOrder bo = byteOrder(); - byte* pData = nullptr; + const byte* pData = nullptr; size_t size = 0; IoCloser closer(*io_); // Ensure that this is the correct image type @@ -104,7 +104,7 @@ ByteOrder Cr2Parser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xmp } WriteMethod Cr2Parser::encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData, - IptcData& iptcData, XmpData& xmpData) { + const IptcData& iptcData, const XmpData& xmpData) { // Delete IFDs which do not occur in TIFF images static constexpr auto filteredIfds = std::array{ IfdId::panaRawId, diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 4ca559b543..f7e6b65b28 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -837,7 +837,7 @@ void CrwMap::encodeBasic(const Image& image, const CrwMapping& pCrwMapping, Ciff void CrwMap::encode0x0805(const Image& image, const CrwMapping& pCrwMapping, CiffHeader& pHead) { std::string comment = image.comment(); - CiffComponent* cc = pHead.findComponent(pCrwMapping.crwTagId_, pCrwMapping.crwDir_); + auto cc = pHead.findComponent(pCrwMapping.crwTagId_, pCrwMapping.crwDir_); if (!comment.empty()) { auto size = comment.size(); if (cc && cc->size() > size) diff --git a/src/datasets.cpp b/src/datasets.cpp index 3d257b2208..cd5012300e 100644 --- a/src/datasets.cpp +++ b/src/datasets.cpp @@ -481,7 +481,7 @@ uint16_t IptcDataSets::recordId(const std::string& recordName) { } void IptcDataSets::dataSetList(std::ostream& os) { - for (auto&& record : records_) { + for (const auto& record : records_) { for (int j = 0; record && record[j].number_ != 0xffff; ++j) { os << record[j] << "\n"; } diff --git a/src/image.cpp b/src/image.cpp index eaa78c8fd4..fb70362af5 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -650,7 +650,7 @@ void Image::appendIccProfile(const uint8_t* bytes, size_t size, bool bTestValid) } } -void Image::checkIccProfile() { +void Image::checkIccProfile() const { if (iccProfile_.size() < sizeof(long)) { throw Error(ErrorCode::kerInvalidIccProfile); } diff --git a/src/orfimage.cpp b/src/orfimage.cpp index ed60f95a00..d0cd15d922 100644 --- a/src/orfimage.cpp +++ b/src/orfimage.cpp @@ -90,7 +90,7 @@ void OrfImage::writeMetadata() { std::cerr << "Writing ORF file " << io_->path() << "\n"; #endif ByteOrder bo = byteOrder(); - byte* pData = nullptr; + const byte* pData = nullptr; size_t size = 0; IoCloser closer(*io_); // Ensure that this is the correct image type @@ -116,7 +116,7 @@ ByteOrder OrfParser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xmp } WriteMethod OrfParser::encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData, - IptcData& iptcData, XmpData& xmpData) { + const IptcData& iptcData, const XmpData& xmpData) { // Delete IFDs which do not occur in TIFF images static constexpr auto filteredIfds = { IfdId::panaRawId, diff --git a/src/preview.cpp b/src/preview.cpp index b281253d12..a6093a3133 100644 --- a/src/preview.cpp +++ b/src/preview.cpp @@ -981,11 +981,11 @@ uint32_t PreviewImage::size() const { return static_cast(preview_.size()); } -std::string PreviewImage::mimeType() const { +const std::string& PreviewImage::mimeType() const { return properties_.mimeType_; } -std::string PreviewImage::extension() const { +const std::string& PreviewImage::extension() const { return properties_.extension_; } diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index 3ab2d659cb..d94152d5db 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -1172,7 +1172,7 @@ size_t TiffComponent::writeImage(IoWrapper& ioWrapper, ByteOrder byteOrder) cons size_t TiffDirectory::doWriteImage(IoWrapper& ioWrapper, ByteOrder byteOrder) const { size_t len = 0; - TiffComponent* pSubIfd = nullptr; + const TiffComponent* pSubIfd = nullptr; for (const auto& component : components_) { if (component->tag() == 0x014a) { // Hack: delay writing of sub-IFD image data to get the order correct diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp index e2743015a8..c91f1da53c 100644 --- a/src/tiffimage.cpp +++ b/src/tiffimage.cpp @@ -166,7 +166,7 @@ void TiffImage::writeMetadata() { std::cerr << "Writing TIFF file " << io_->path() << "\n"; #endif ByteOrder bo = byteOrder(); - byte* pData = nullptr; + const byte* pData = nullptr; size_t size = 0; IoCloser closer(*io_); // Ensure that this is the correct image type @@ -217,7 +217,7 @@ ByteOrder TiffParser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xm } // TiffParser::decode WriteMethod TiffParser::encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, ExifData& exifData, - IptcData& iptcData, XmpData& xmpData) { + const IptcData& iptcData, const XmpData& xmpData) { // Delete IFDs which do not occur in TIFF images static constexpr auto filteredIfds = std::array{ IfdId::panaRawId,