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/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/src/basicio.cpp b/src/basicio.cpp index e44c0372b8..7b092c6a74 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -931,13 +931,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/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 c086bc7f17..f51fd585e9 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/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/quicktimevideo.cpp b/src/quicktimevideo.cpp index 583f595937..88ac1e92bf 100644 --- a/src/quicktimevideo.cpp +++ b/src/quicktimevideo.cpp @@ -1430,9 +1430,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) @@ -1551,9 +1549,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 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.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 10c1dcf95d..cae603e521 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) { @@ -2620,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/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.cpp b/src/tiffcomposite_int.cpp index ae0d2c1b22..24436c020b 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 { @@ -1431,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/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/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index 7c59309633..05e880b5a0 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) @@ -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; 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 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 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);