From 1296888ffbaa8b44d93e016caf9148c352dfa964 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 17 Nov 2025 15:30:02 -0800 Subject: [PATCH 1/8] move signature_ out of line Consistent with the rest. Signed-off-by: Rosen Penev --- src/crwimage_int.cpp | 4 +++- src/crwimage_int.hpp | 4 ++-- src/tags_int.cpp | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index d6f2acfaad..8657f74414 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -135,6 +135,8 @@ const CiffComponent::UniquePtr& CiffDirectory::doAdd(UniquePtr component) { return components_.emplace_back(std::move(component)); } // CiffDirectory::doAdd +const byte CiffHeader::signature_[] = {'H', 'E', 'A', 'P', 'C', 'C', 'D', 'R'}; + void CiffHeader::read(const byte* pData, size_t size) { if (size < 14) throw Error(ErrorCode::kerNotACrwImage); @@ -281,7 +283,7 @@ void CiffHeader::write(Blob& blob) const { ul2Data(buf, offset_, byteOrder_); append(blob, buf, 4); o += 4; - append(blob, reinterpret_cast(signature_), 8); + append(blob, signature_, 8); o += 8; // Pad as needed if (!pPadding_.empty()) { diff --git a/src/crwimage_int.hpp b/src/crwimage_int.hpp index 92d231b937..15e0169468 100644 --- a/src/crwimage_int.hpp +++ b/src/crwimage_int.hpp @@ -413,7 +413,7 @@ class CiffHeader { //@} //! Return a pointer to the Canon CRW signature. - static const char* signature() { + static auto signature() { return signature_; } @@ -451,7 +451,7 @@ class CiffHeader { private: // DATA - static constexpr auto signature_ = "HEAPCCDR"; //!< Canon CRW signature + static const byte signature_[]; //!< Canon CRW signature std::unique_ptr pRootDir_; //!< Pointer to the root directory ByteOrder byteOrder_ = littleEndian; //!< Applicable byte order diff --git a/src/tags_int.cpp b/src/tags_int.cpp index 10c1dcf95d..f64aa9f3c1 100644 --- a/src/tags_int.cpp +++ b/src/tags_int.cpp @@ -2474,8 +2474,9 @@ const TagInfo* mnTagList() { } bool isMakerIfd(IfdId ifdId) { - auto ii = Exiv2::find(groupInfo, ifdId); - return ii && strcmp(ii->ifdName_, "Makernote") == 0; + if (auto ii = Exiv2::find(groupInfo, ifdId)) + return std::string_view("Makernote") == ii->ifdName_; + return false; } bool isExifIfd(IfdId ifdId) { From e1b272ff5bfd9106fb6d518a6897abdaf9e3e6d8 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 14 Nov 2025 13:08:10 -0800 Subject: [PATCH 2/8] fix some MSVC warnings Signed-off-by: Rosen Penev --- src/basicio.cpp | 6 +++--- src/convert.cpp | 2 +- src/tiffvisitor_int.cpp | 2 +- src/xmpsidecar.cpp | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/basicio.cpp b/src/basicio.cpp index 6b42df5bde..154000f4bc 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -930,13 +930,13 @@ std::string XPathIo::writeDataToFile(const std::string& orgPath) { #endif std::ofstream fs(path, std::ios::out | std::ios::binary | std::ios::trunc); // read stdin and write to the temp file. - char readBuf[100 * 1024]; + auto readBuf = std::make_unique(100 * 1024); std::streamsize readBufSize = 0; do { - std::cin.read(readBuf, sizeof(readBuf)); + std::cin.read(readBuf.get(), 100 * 1024); readBufSize = std::cin.gcount(); if (readBufSize > 0) { - fs.write(readBuf, readBufSize); + fs.write(readBuf.get(), readBufSize); } } while (readBufSize); fs.close(); diff --git a/src/convert.cpp b/src/convert.cpp index 1cc31b2beb..0cd22f4f64 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -751,7 +751,7 @@ void Converter::cnvExifVersion(const char* from, const char* to) { std::string value; value.reserve(count); for (size_t i = 0; i < count; ++i) { - value.push_back(pos->toInt64(i)); + value.push_back(pos->toUint32(i)); } (*xmpData_)[to] = value; if (erase_) diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index 7c59309633..dcf92bd605 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -355,7 +355,7 @@ void TiffDecoder::decodeCanonAFInfo(const TiffEntryBase* object) { std::vector uint; for (size_t i = 0; i < object->pValue()->count(); i++) { ints.push_back(object->pValue()->toInt64(i)); - uint.push_back(object->pValue()->toInt64(i)); + uint.push_back(object->pValue()->toUint32(i)); } // Check this is AFInfo2 (ints[0] = bytes in object) if (ints.front() != static_cast(object->pValue()->count()) * 2) diff --git a/src/xmpsidecar.cpp b/src/xmpsidecar.cpp index 94623f94b7..269cd60b86 100644 --- a/src/xmpsidecar.cpp +++ b/src/xmpsidecar.cpp @@ -59,9 +59,9 @@ void XmpSidecar::readMetadata() { // Read the XMP packet from the IO stream std::string xmpPacket; const long len = 64 * 1024; - byte buf[len]; - while (auto l = io_->read(buf, len)) { - xmpPacket.append(reinterpret_cast(buf), l); + auto buf = std::make_unique(len); + while (auto l = io_->read(buf.get(), len)) { + xmpPacket.append(reinterpret_cast(buf.get()), l); } if (io_->error()) throw Error(ErrorCode::kerFailedToReadImageData); From 2bb905a87885e5ef5cbb310e303c317578d9b852 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 25 Apr 2025 12:09:10 -0700 Subject: [PATCH 3/8] add implicit headers Signed-off-by: Rosen Penev --- app/app_utils.cpp | 1 + src/error.cpp | 2 ++ src/pgfimage.cpp | 3 +++ src/tiffcomposite_int.cpp | 7 +++++++ 4 files changed, 13 insertions(+) diff --git a/app/app_utils.cpp b/app/app_utils.cpp index d36694b2d1..e2fedf9996 100644 --- a/app/app_utils.cpp +++ b/app/app_utils.cpp @@ -2,6 +2,7 @@ #include "app_utils.hpp" #include +#include #include #include diff --git a/src/error.cpp b/src/error.cpp index 5235b12b06..d4b2008722 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -7,6 +7,8 @@ // + standard includes #include #include +#include +#include namespace { //! Complete list of Exiv2 exception error messages diff --git a/src/pgfimage.cpp b/src/pgfimage.cpp index 394cf1d9e0..187d8e15fc 100644 --- a/src/pgfimage.cpp +++ b/src/pgfimage.cpp @@ -9,10 +9,13 @@ #include "error.hpp" #include "futils.hpp" #include "image.hpp" +#include "types.hpp" #include +#include #include #include +#include #ifdef EXIV2_DEBUG_MESSAGES #include diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index ae0d2c1b22..b9d5b5e7a6 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -17,10 +17,17 @@ #include "value.hpp" #include +#include +#include +#include #include +#include #include +#include #include #include +#include +#include // ***************************************************************************** namespace { From 615de0e8a550c9cd66397e7a181fb783d014c556 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 17 Nov 2025 13:37:34 -0800 Subject: [PATCH 4/8] header reductions Signed-off-by: Rosen Penev --- app/exiv2app.hpp | 1 - include/exiv2/basicio.hpp | 44 ++++++++++++++++++------------------- include/exiv2/photoshop.hpp | 23 +++++++++---------- include/exiv2/preview.hpp | 1 - src/helper_functions.cpp | 3 ++- src/sonymn_int.hpp | 5 +++-- src/tags_int.hpp | 1 - src/tiffcomposite_int.hpp | 1 + src/tifffwd_int.hpp | 1 - src/tiffimage_int.hpp | 2 ++ unitTests/test_basicio.cpp | 1 + 11 files changed, 43 insertions(+), 40 deletions(-) diff --git a/app/exiv2app.hpp b/app/exiv2app.hpp index 8e7dcdd033..6fbfb38abe 100644 --- a/app/exiv2app.hpp +++ b/app/exiv2app.hpp @@ -13,7 +13,6 @@ #include #include "getopt.hpp" -#include "types.hpp" // + standard includes #include diff --git a/include/exiv2/basicio.hpp b/include/exiv2/basicio.hpp index d8d9a05320..a60e5e2a13 100644 --- a/include/exiv2/basicio.hpp +++ b/include/exiv2/basicio.hpp @@ -9,7 +9,6 @@ // included header files #include "config.h" #include "error.hpp" -#include "types.hpp" // + standard includes #include @@ -17,6 +16,7 @@ // ***************************************************************************** // namespace extensions namespace Exiv2 { +struct DataBuf; // ***************************************************************************** // class definitions @@ -77,7 +77,7 @@ class EXIV2API BasicIo { @return Number of bytes written to IO source successfully;
0 if failure; */ - virtual size_t write(const byte* data, size_t wcount) = 0; + virtual size_t write(const unsigned char* data, size_t wcount) = 0; /*! @brief Write data that is read from another BasicIo instance to the IO source. Current IO position is advanced by the number @@ -95,7 +95,7 @@ class EXIV2API BasicIo { @return The value of the byte written if successful;
EOF if failure; */ - virtual int putb(byte data) = 0; + virtual int putb(unsigned char data) = 0; /*! @brief Read data from the IO source. Reading starts at the current IO position and the position is advanced by the number of bytes @@ -119,7 +119,7 @@ class EXIV2API BasicIo { @return Number of bytes read from IO source successfully;
0 if failure; */ - virtual size_t read(byte* buf, size_t rcount) = 0; + virtual size_t read(unsigned char* buf, size_t rcount) = 0; /*! @brief Safe version of `read()` that checks for errors and throws an exception if the read was unsuccessful. @@ -130,7 +130,7 @@ class EXIV2API BasicIo { read if \em rcount bytes are not available. @param err Error code to use if an exception is thrown. */ - void readOrThrow(byte* buf, size_t rcount, ErrorCode err = ErrorCode::kerCorruptedMetadata); + void readOrThrow(unsigned char* buf, size_t rcount, ErrorCode err = ErrorCode::kerCorruptedMetadata); /*! @brief Read one byte from the IO source. Current IO position is advanced by one byte. @@ -181,7 +181,7 @@ class EXIV2API BasicIo { @return A pointer to the mapped area. @throw Error In case of failure. */ - virtual byte* mmap(bool isWriteable = false) = 0; + virtual unsigned char* mmap(bool isWriteable = false) = 0; /*! @brief Remove a mapping established with mmap(). If the mapped area is writeable, this ensures that changes are written back. @@ -230,7 +230,7 @@ class EXIV2API BasicIo { /*! @brief this is allocated and populated by mmap() */ - byte* bigBlock_{}; + unsigned char* bigBlock_{}; //@} }; // class BasicIo @@ -332,7 +332,7 @@ class EXIV2API FileIo : public BasicIo { @return Number of bytes written to the file successfully;
0 if failure; */ - size_t write(const byte* data, size_t wcount) override; + size_t write(const unsigned char* data, size_t wcount) override; /*! @brief Write data that is read from another BasicIo instance to the file. The file position is advanced by the number @@ -350,7 +350,7 @@ class EXIV2API FileIo : public BasicIo { @return The value of the byte written if successful;
EOF if failure; */ - int putb(byte data) override; + int putb(unsigned char data) override; /*! @brief Read data from the file. Reading starts at the current file position and the position is advanced by the number of @@ -374,7 +374,7 @@ class EXIV2API FileIo : public BasicIo { @return Number of bytes read from the file successfully;
0 if failure; */ - size_t read(byte* buf, size_t rcount) override; + size_t read(unsigned char* buf, size_t rcount) override; /*! @brief Read one byte from the file. The file position is advanced by one byte. @@ -415,7 +415,7 @@ class EXIV2API FileIo : public BasicIo { @return A pointer to the mapped area. @throw Error In case of failure. */ - byte* mmap(bool isWriteable = false) override; + unsigned char* mmap(bool isWriteable = false) override; /*! @brief Remove a mapping established with mmap(). If the mapped area is writeable, this ensures that changes are written back to the @@ -499,7 +499,7 @@ class EXIV2API MemIo : public BasicIo { @param data Pointer to data. Data must be at least \em size bytes long @param size Number of bytes to copy. */ - MemIo(const byte* data, size_t size); + MemIo(const unsigned char* data, size_t size); //! Destructor. Releases all managed memory ~MemIo() override; //@} @@ -528,7 +528,7 @@ class EXIV2API MemIo : public BasicIo { @return Number of bytes written to the memory block successfully;
0 if failure; */ - size_t write(const byte* data, size_t wcount) override; + size_t write(const unsigned char* data, size_t wcount) override; /*! @brief Write data that is read from another BasicIo instance to the memory block. If needed, the size of the internal memory @@ -547,7 +547,7 @@ class EXIV2API MemIo : public BasicIo { @return The value of the byte written if successful;
EOF if failure; */ - int putb(byte data) override; + int putb(unsigned char data) override; /*! @brief Read data from the memory block. Reading starts at the current IO position and the position is advanced by the number of @@ -571,7 +571,7 @@ class EXIV2API MemIo : public BasicIo { @return Number of bytes read from the memory block successfully;
0 if failure; */ - size_t read(byte* buf, size_t rcount) override; + size_t read(unsigned char* buf, size_t rcount) override; /*! @brief Read one byte from the memory block. The IO position is advanced by one byte. @@ -606,7 +606,7 @@ class EXIV2API MemIo : public BasicIo { returned pointer remains valid and allocated as long as the MemIo object exists. */ - byte* mmap(bool /*isWriteable*/ = false) override; + unsigned char* mmap(bool /*isWriteable*/ = false) override; int munmap() override; //@} @@ -739,7 +739,7 @@ class EXIV2API RemoteIo : public BasicIo { @brief Not support this method. @return 0 means failure */ - size_t write(const byte* data, size_t wcount) override; + size_t write(const unsigned char* data, size_t wcount) override; /*! @brief Write data that is read from another BasicIo instance to the remote file. @@ -760,7 +760,7 @@ class EXIV2API RemoteIo : public BasicIo { @brief Not support @return 0 means failure */ - int putb(byte data) override; + int putb(unsigned char data) override; /*! @brief Read data from the memory blocks. Reading starts at the current IO position and the position is advanced by the number of @@ -788,7 +788,7 @@ class EXIV2API RemoteIo : public BasicIo { @return Number of bytes read from the memory block successfully;
0 if failure; */ - size_t read(byte* buf, size_t rcount) override; + size_t read(unsigned char* buf, size_t rcount) override; /*! @brief Read one byte from the memory blocks. The IO position is advanced by one byte. @@ -820,7 +820,7 @@ class EXIV2API RemoteIo : public BasicIo { @brief Not support @return NULL */ - byte* mmap(bool /*isWriteable*/ = false) override; + unsigned char* mmap(bool /*isWriteable*/ = false) override; /*! @brief Not support @return 0 @@ -913,10 +913,10 @@ class EXIV2API CurlIo : public RemoteIo { /*! @brief Write access is only available for some protocols. This method - will call RemoteIo::write(const byte* data, long wcount) if the write + will call RemoteIo::write(const unsigned char* data, long wcount) if the write access is available for the protocol. Otherwise, it throws the Error. */ - size_t write(const byte* data, size_t wcount) override; + size_t write(const unsigned char* data, size_t wcount) override; /*! @brief Write access is only available for some protocols. This method will call RemoteIo::write(BasicIo& src) if the write access is available diff --git a/include/exiv2/photoshop.hpp b/include/exiv2/photoshop.hpp index a13deed5dd..f23a817362 100644 --- a/include/exiv2/photoshop.hpp +++ b/include/exiv2/photoshop.hpp @@ -5,12 +5,13 @@ #include "exiv2lib_export.h" -#include "types.hpp" - #include +#include +#include namespace Exiv2 { // Forward declarations +struct DataBuf; class IptcData; /// @brief Helper class, has methods to deal with %Photoshop "Information Resource Blocks" (IRBs). @@ -26,13 +27,13 @@ struct EXIV2API Photoshop { /// @return true if the IRB marker is known /// @todo This should be an implementation detail and not exposed in the API. An attacker could try to pass /// a smaller buffer or null pointer. - static bool isIrb(const byte* pPsData); + static bool isIrb(const unsigned char* pPsData); /// @brief Validates all IRBs /// @param pPsData Existing IRB buffer /// @param sizePsData Size of the IRB buffer, may be 0 /// @return true if all IRBs are valid;
false otherwise - static bool valid(const byte* pPsData, size_t sizePsData); + static bool valid(const unsigned char* pPsData, size_t sizePsData); /// @brief Locates the data for a %Photoshop tag in a %Photoshop formatted memory buffer. /// Operates on raw data to simplify reuse. @@ -47,23 +48,23 @@ struct EXIV2API Photoshop { /// @return 0 if successful;
/// 3 if no data for psTag was found in pPsData;
/// -2 if the pPsData buffer does not contain valid data. - static int locateIrb(const byte* pPsData, size_t sizePsData, uint16_t psTag, const byte** record, uint32_t& sizeHdr, - uint32_t& sizeData); + static int locateIrb(const unsigned char* pPsData, size_t sizePsData, uint16_t psTag, const unsigned char** record, + uint32_t& sizeHdr, uint32_t& sizeData); /// @brief Forwards to locateIrb() with \em psTag = \em iptc_ - static int locateIptcIrb(const byte* pPsData, size_t sizePsData, const byte** record, uint32_t& sizeHdr, - uint32_t& sizeData); + static int locateIptcIrb(const unsigned char* pPsData, size_t sizePsData, const unsigned char** record, + uint32_t& sizeHdr, uint32_t& sizeData); /// @brief Forwards to locatePreviewIrb() with \em psTag = \em preview_ - static int locatePreviewIrb(const byte* pPsData, size_t sizePsData, const byte** record, uint32_t& sizeHdr, - uint32_t& sizeData); + static int locatePreviewIrb(const unsigned char* pPsData, size_t sizePsData, const unsigned char** record, + uint32_t& sizeHdr, uint32_t& sizeData); /// @brief Set the new IPTC IRB, keeps existing IRBs but removes the IPTC block if there is no new IPTC data to write. /// @param pPsData Existing IRB buffer /// @param sizePsData Size of the IRB buffer, may be 0 /// @param iptcData Iptc data to embed, may be empty /// @return A data buffer containing the new IRB buffer, may have 0 size - static DataBuf setIptcIrb(const byte* pPsData, size_t sizePsData, const IptcData& iptcData); + static DataBuf setIptcIrb(const unsigned char* pPsData, size_t sizePsData, const IptcData& iptcData); }; } // namespace Exiv2 diff --git a/include/exiv2/preview.hpp b/include/exiv2/preview.hpp index 2ecf2359cd..dffb9be5aa 100644 --- a/include/exiv2/preview.hpp +++ b/include/exiv2/preview.hpp @@ -17,7 +17,6 @@ // namespace extensions namespace Exiv2 { class Image; -struct DataBuf; // ***************************************************************************** // class definitions diff --git a/src/helper_functions.cpp b/src/helper_functions.cpp index eed4ae1d81..2a1bbfdd63 100644 --- a/src/helper_functions.cpp +++ b/src/helper_functions.cpp @@ -5,6 +5,7 @@ #include "basicio.hpp" #include "convert.hpp" #include "enforce.hpp" +#include "types.hpp" #include #include @@ -20,7 +21,7 @@ std::string string_from_unterminated(const char* data, size_t data_length) { namespace Exiv2 { uint64_t readQWORDTag(const BasicIo::UniquePtr& io) { Internal::enforce(QWORD <= io->size() - io->tell(), Exiv2::ErrorCode::kerCorruptedMetadata); - DataBuf FieldBuf = io->read(QWORD); + auto FieldBuf = io->read(QWORD); return FieldBuf.read_uint64(0, littleEndian); } diff --git a/src/sonymn_int.hpp b/src/sonymn_int.hpp index faa347845b..10aaecde06 100644 --- a/src/sonymn_int.hpp +++ b/src/sonymn_int.hpp @@ -12,6 +12,7 @@ namespace Exiv2 { class ExifData; class Value; +struct DataBuf; struct TagInfo; namespace Internal { // ***************************************************************************** @@ -144,8 +145,8 @@ class SonyMakerNote { }; // class SonyMakerNote -DataBuf sonyTagDecipher(uint16_t, const byte*, size_t, TiffComponent*); -DataBuf sonyTagEncipher(uint16_t, const byte*, size_t, TiffComponent*); +DataBuf sonyTagDecipher(uint16_t, const unsigned char*, size_t, TiffComponent*); +DataBuf sonyTagEncipher(uint16_t, const unsigned char*, size_t, TiffComponent*); } // namespace Internal } // namespace Exiv2 diff --git a/src/tags_int.hpp b/src/tags_int.hpp index e20c1b6983..6fa35360da 100644 --- a/src/tags_int.hpp +++ b/src/tags_int.hpp @@ -5,7 +5,6 @@ // ***************************************************************************** // included header files -#include "types.hpp" #include "value.hpp" #include "i18n.h" diff --git a/src/tiffcomposite_int.hpp b/src/tiffcomposite_int.hpp index 7bbd3d3aff..87e0e9db81 100644 --- a/src/tiffcomposite_int.hpp +++ b/src/tiffcomposite_int.hpp @@ -6,6 +6,7 @@ // ***************************************************************************** // included header files #include "tifffwd_int.hpp" +#include "types.hpp" #include diff --git a/src/tifffwd_int.hpp b/src/tifffwd_int.hpp index a8083c8fe3..e14e1797a6 100644 --- a/src/tifffwd_int.hpp +++ b/src/tifffwd_int.hpp @@ -5,7 +5,6 @@ // ***************************************************************************** // included header files -#include "types.hpp" // + standard includes #include diff --git a/src/tiffimage_int.hpp b/src/tiffimage_int.hpp index 9880bc6f1c..1de0475aca 100644 --- a/src/tiffimage_int.hpp +++ b/src/tiffimage_int.hpp @@ -6,6 +6,7 @@ // ***************************************************************************** // included header files #include "tifffwd_int.hpp" +#include "types.hpp" #include #include @@ -17,6 +18,7 @@ class BasicIo; class ExifData; class IptcData; class XmpData; +struct DataBuf; namespace Internal { /*! diff --git a/unitTests/test_basicio.cpp b/unitTests/test_basicio.cpp index 4622cfd5d9..4c1a7fa30f 100644 --- a/unitTests/test_basicio.cpp +++ b/unitTests/test_basicio.cpp @@ -2,6 +2,7 @@ #include #include +#include #include From 8ef9e9ccc860ab6ed3b1742f9a52202d6e9c8ced Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 8 Sep 2025 15:50:43 -0700 Subject: [PATCH 5/8] get rid of maybe_unused ifdef properly. Signed-off-by: Rosen Penev --- src/webpimage.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/webpimage.cpp b/src/webpimage.cpp index cd89c1b30f..3771101219 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -21,8 +21,9 @@ #include #include +#ifdef EXIV2_DEBUG_MESSAGES namespace { -[[maybe_unused]] std::string binaryToHex(const uint8_t* data, size_t size) { +std::string binaryToHex(const uint8_t* data, size_t size) { std::stringstream hexOutput; auto tl = size / 16 * 16; @@ -67,6 +68,7 @@ namespace { return hexOutput.str(); } } // namespace +#endif // ***************************************************************************** // class member definitions From 1f2d33258e618d09d1a3144665e2ac1562e0bada Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 18 Oct 2025 16:04:06 -0700 Subject: [PATCH 6/8] std::max Signed-off-by: Rosen Penev --- src/quicktimevideo.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/quicktimevideo.cpp b/src/quicktimevideo.cpp index 44229f7480..93fc6a6770 100644 --- a/src/quicktimevideo.cpp +++ b/src/quicktimevideo.cpp @@ -1434,9 +1434,7 @@ void QuickTimeVideo::mediaHeaderDecoder(size_t size) { xmpData_["Xmp.video.MediaTimeScale"] = buf.read_uint32(0, bigEndian); else if (currentStream_ == Audio) xmpData_["Xmp.audio.MediaTimeScale"] = buf.read_uint32(0, bigEndian); - time_scale = buf.read_uint32(0, bigEndian); - if (time_scale <= 0) - time_scale = 1; + time_scale = std::max(1U, buf.read_uint32(0, bigEndian)); break; case MediaDuration: if (currentStream_ == Video) @@ -1555,9 +1553,7 @@ void QuickTimeVideo::movieHeaderDecoder(size_t size) { break; case TimeScale: xmpData_["Xmp.video.TimeScale"] = buf.read_uint32(0, bigEndian); - timeScale_ = buf.read_uint32(0, bigEndian); - if (timeScale_ <= 0) - timeScale_ = 1; + timeScale_ = std::max(1U, buf.read_uint32(0, bigEndian)); break; case Duration: if (timeScale_ != 0) { // To prevent division by zero From a4cefa82110c8e4918ef710c94731e9517aeb22a Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 21 Oct 2025 17:12:28 -0700 Subject: [PATCH 7/8] replace template with auto A little simpler. Signed-off-by: Rosen Penev --- src/types.cpp | 3 +-- src/utils.hpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/types.cpp b/src/types.cpp index cb110c26bb..8f2c5c5d9b 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -211,8 +211,7 @@ std::ostream& operator<<(std::ostream& os, const Rational& r) { return os << r.first << "/" << r.second; } -template -static std::istream& fromStreamToRational(std::istream& is, T& r) { +static std::istream& fromStreamToRational(std::istream& is, auto& r) { // http://dev.exiv2.org/boards/3/topics/1912?r=1915 if (std::tolower(is.peek()) == 'f') { char F = 0; diff --git a/src/utils.hpp b/src/utils.hpp index 02a41ac709..a3297b4b11 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -6,8 +6,7 @@ namespace Exiv2::Internal { -template -constexpr bool contains(std::string_view s, T c) { +constexpr bool contains(std::string_view s, auto c) { #ifdef __cpp_lib_string_contains return s.contains(c); #else From fae861e8edc85db49cae82352f6d51a80179b35b Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 17 Nov 2025 16:12:16 -0800 Subject: [PATCH 8/8] reduce some TagInfo indentation Signed-off-by: Rosen Penev --- src/tags.cpp | 24 +++++++++++------------- src/tags_int.cpp | 2 +- src/tiffcomposite_int.cpp | 12 ++++-------- src/tiffvisitor_int.cpp | 2 +- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/tags.cpp b/src/tags.cpp index 885a799793..4149cad8a6 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -74,18 +74,16 @@ bool GroupInfo::operator==(const GroupName& groupName) const { } const char* ExifTags::sectionName(const ExifKey& key) { - const TagInfo* ti = tagInfo(key.tag(), key.ifdId()); - if (!ti) - return sectionInfo[static_cast(unknownTag.sectionId_)].name_; - return sectionInfo[static_cast(ti->sectionId_)].name_; + if (auto ti = tagInfo(key.tag(), key.ifdId())) + return sectionInfo[static_cast(ti->sectionId_)].name_; + return sectionInfo[static_cast(unknownTag.sectionId_)].name_; } /// \todo not used internally. At least we should test it uint16_t ExifTags::defaultCount(const ExifKey& key) { - const TagInfo* ti = tagInfo(key.tag(), key.ifdId()); - if (!ti) - return unknownTag.count_; - return ti->count_; + if (auto ti = tagInfo(key.tag(), key.ifdId())) + return ti->count_; + return unknownTag.count_; } const char* ExifTags::ifdName(const std::string& groupName) { @@ -236,12 +234,12 @@ ExifKey::ExifKey(uint16_t tag, const std::string& groupName) : p_(std::make_uniq if (!Internal::isExifIfd(ifdId) && !Internal::isMakerIfd(ifdId)) { throw Error(ErrorCode::kerInvalidIfdId, ifdId); } - const TagInfo* ti = tagInfo(tag, ifdId); - if (!ti) { - throw Error(ErrorCode::kerInvalidIfdId, ifdId); + if (auto ti = tagInfo(tag, ifdId)) { + p_->groupName_ = groupName; + p_->makeKey(tag, ifdId, ti); + return; } - p_->groupName_ = groupName; - p_->makeKey(tag, ifdId, ti); + throw Error(ErrorCode::kerInvalidIfdId, ifdId); } ExifKey::ExifKey(const TagInfo& ti) : p_(std::make_unique()) { diff --git a/src/tags_int.cpp b/src/tags_int.cpp index f64aa9f3c1..cae603e521 100644 --- a/src/tags_int.cpp +++ b/src/tags_int.cpp @@ -2621,7 +2621,7 @@ URational exposureTime(float shutterSpeedValue) { } uint16_t tagNumber(const std::string& tagName, IfdId ifdId) { - const TagInfo* ti = tagInfo(tagName, ifdId); + auto ti = tagInfo(tagName, ifdId); if (ti && ti->tag_ != 0xffff) return ti->tag_; if (!isHex(tagName, 4, "0x")) diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index b9d5b5e7a6..24436c020b 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -1438,14 +1438,10 @@ static const TagInfo* findTagInfo(uint16_t tag, IfdId group) { return Internal::gpsTagList(); return group == IfdId::exifId ? Internal::exifTagList() : nullptr; }(); - if (!tags) - return nullptr; - - for (size_t idx = 0; tags[idx].tag_ != 0xffff; ++idx) { - if (tags[idx].tag_ == tag) { - return tags + idx; - } - } + if (tags) + for (size_t idx = 0; tags[idx].tag_ != 0xffff; ++idx) + if (tags[idx].tag_ == tag) + return tags + idx; return nullptr; } diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index dcf92bd605..05e880b5a0 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -393,7 +393,7 @@ void TiffDecoder::decodeCanonAFInfo(const TiffEntryBase* object) { } for (const auto& [tag, size, bSigned] : records) { - const TagInfo* pTags = ExifTags::tagList("Canon"); + auto pTags = ExifTags::tagList("Canon"); if (auto pTag = findTag(pTags, tag)) { auto v = Exiv2::Value::create(bSigned ? Exiv2::signedShort : Exiv2::unsignedShort); std::string s;