diff --git a/app/exiv2.cpp b/app/exiv2.cpp
index 8f495047..310b4dd8 100644
--- a/app/exiv2.cpp
+++ b/app/exiv2.cpp
@@ -1092,7 +1092,9 @@ cleanup:
// local implementations
namespace {
bool parseTime(const std::string& ts, int64_t& time) {
- std::string hstr, mstr, sstr;
+ std::string hstr;
+ std::string mstr;
+ std::string sstr;
auto cts = new char[ts.length() + 1];
strcpy(cts, ts.c_str());
auto tmp = ::strtok(cts, ":");
@@ -1107,7 +1109,9 @@ bool parseTime(const std::string& ts, int64_t& time) {
delete[] cts;
int sign = 1;
- int64_t hh(0), mm(0), ss(0);
+ int64_t hh = 0;
+ int64_t mm = 0;
+ int64_t ss = 0;
// [-]HH part
if (!Util::strtol(hstr.c_str(), hh))
return false;
diff --git a/include/exiv2/iptc.hpp b/include/exiv2/iptc.hpp
index 9329add1..9c80f39a 100644
--- a/include/exiv2/iptc.hpp
+++ b/include/exiv2/iptc.hpp
@@ -177,7 +177,7 @@ class EXIV2API IptcData {
@return 0 if successful;
6 if the dataset already exists and is not repeatable
*/
- int add(const IptcKey& key, Value* value);
+ int add(const IptcKey& key, const Value* value);
/*!
@brief Add a copy of the Iptcdatum to the IPTC metadata. A check
for non-repeatable datasets is performed.
@@ -244,7 +244,7 @@ class EXIV2API IptcData {
[[nodiscard]] const_iterator findId(uint16_t dataset, uint16_t record = IptcDataSets::application2) const;
//! Return true if there is no IPTC metadata
[[nodiscard]] bool empty() const {
- return count() == 0;
+ return iptcMetadata_.empty();
}
//! Get the number of metadata entries
diff --git a/include/exiv2/quicktimevideo.hpp b/include/exiv2/quicktimevideo.hpp
index 1d3f5c5c..84687d88 100644
--- a/include/exiv2/quicktimevideo.hpp
+++ b/include/exiv2/quicktimevideo.hpp
@@ -200,7 +200,8 @@ class EXIV2API QuickTimeVideo : public Image {
//! Variable to check the end of metadata traversing.
bool continueTraversing_ = false;
//! Variable to store height and width of a video frame.
- uint64_t height_ = 0, width_ = 0;
+ uint64_t height_ = 0;
+ uint64_t width_ = 0;
}; // QuickTimeVideo End
diff --git a/include/exiv2/riffvideo.hpp b/include/exiv2/riffvideo.hpp
index 7610a0fc..cbe4a18b 100644
--- a/include/exiv2/riffvideo.hpp
+++ b/include/exiv2/riffvideo.hpp
@@ -48,7 +48,7 @@ class EXIV2API RiffVideo : public Image {
uint64_t size_ = 0;
public:
- explicit HeaderReader(BasicIo::UniquePtr& io);
+ explicit HeaderReader(const BasicIo::UniquePtr& io);
[[nodiscard]] uint64_t getSize() const {
return size_;
@@ -59,9 +59,9 @@ class EXIV2API RiffVideo : public Image {
}
};
- void readList(HeaderReader& header_);
+ void readList(const HeaderReader& header_);
- void readChunk(HeaderReader& header_);
+ void readChunk(const HeaderReader& header_);
void decodeBlocks();
diff --git a/include/exiv2/slice.hpp b/include/exiv2/slice.hpp
index f278c7bc..f43afaa0 100644
--- a/include/exiv2/slice.hpp
+++ b/include/exiv2/slice.hpp
@@ -48,7 +48,8 @@ struct SliceBase {
* lower and upper bounds of the slice with respect to the
* container/array stored in storage_
*/
- const size_t begin_, end_;
+ size_t begin_;
+ size_t end_;
};
/*!
@@ -260,10 +261,13 @@ struct MutableSliceBase : public ConstSliceBase {
template
struct ContainerStorage {
using iterator = typename container::iterator;
-
using const_iterator = typename container::const_iterator;
+#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
+ using value_type = std::remove_cv_t;
+#else
using value_type = typename std::remove_cv::type;
+#endif
/*!
* @throw std::out_of_range when end is larger than the container's
@@ -324,7 +328,11 @@ struct ContainerStorage {
*/
template
struct PtrSliceStorage {
+#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
+ using value_type = std::remove_cv_t>;
+#else
using value_type = typename std::remove_cv::type>::type;
+#endif
using iterator = value_type*;
using const_iterator = const value_type*;
@@ -423,7 +431,11 @@ struct Slice : public Internal::MutableSliceBase= 201402L || _MSVC_LANG >= 201402L
+ using value_type = std::remove_cv_t;
+#else
using value_type = typename std::remove_cv::type;
+#endif
/*!
* @brief Construct a slice of the container `cont` starting at `begin`
@@ -476,7 +488,11 @@ struct Slice : public Internal::ConstSliceBase= 201402L || _MSVC_LANG >= 201402L
+ using value_type = std::remove_cv_t;
+#else
using value_type = typename std::remove_cv::type;
+#endif
Slice(const container& cont, size_t begin, size_t end) :
Internal::ConstSliceBase(cont, begin, end) {
diff --git a/include/exiv2/value.hpp b/include/exiv2/value.hpp
index ef5b36f0..9c4e5309 100644
--- a/include/exiv2/value.hpp
+++ b/include/exiv2/value.hpp
@@ -1502,9 +1502,8 @@ template
int ValueType::read(const byte* buf, size_t len, ByteOrder byteOrder) {
value_.clear();
size_t ts = TypeInfo::typeSize(typeId());
- if (ts > 0)
- if (len % ts != 0)
- len = (len / ts) * ts;
+ if (ts > 0 && len % ts != 0)
+ len = (len / ts) * ts;
for (size_t i = 0; i < len; i += ts) {
value_.push_back(getValue(buf + i, byteOrder));
}
diff --git a/src/asfvideo.cpp b/src/asfvideo.cpp
index 029de53c..76a35727 100644
--- a/src/asfvideo.cpp
+++ b/src/asfvideo.cpp
@@ -362,22 +362,22 @@ void AsfVideo::DegradableJPEGMedia() {
void AsfVideo::streamProperties() {
DataBuf streamTypedBuf = io_->read(GUID);
- enum streamTypeInfo { Audio = 1, Video = 2 };
- int stream = 0;
+ enum class streamTypeInfo { Audio = 1, Video = 2 };
+ auto stream = static_cast(0);
auto tag_stream_type = GUIDReferenceTags.find(GUIDTag(streamTypedBuf.data()));
if (tag_stream_type != GUIDReferenceTags.end()) {
if (tag_stream_type->second == "Audio_Media")
- stream = Audio;
+ stream = streamTypeInfo::Audio;
else if (tag_stream_type->second == "Video_Media")
- stream = Video;
+ stream = streamTypeInfo::Video;
io_->seek(io_->tell() + GUID, BasicIo::beg); // ignore Error Correction Type
uint64_t time_offset = readQWORDTag(io_);
- if (stream == Video)
+ if (stream == streamTypeInfo::Video)
xmpData()["Xmp.video.TimeOffset"] = time_offset;
- else if (stream == Audio)
+ else if (stream == streamTypeInfo::Audio)
xmpData()["Xmp.audio.TimeOffset"] = time_offset;
auto specific_data_length = readDWORDTag(io_);
@@ -396,12 +396,10 @@ void AsfVideo::codecList() {
uint16_t codec_type = readWORDTag(io_) * 2;
std::string codec = (codec_type == 1) ? "Xmp.video" : "Xmp.audio";
- uint16_t codec_name_length = readWORDTag(io_) * 2;
- if (codec_name_length)
+ if (uint16_t codec_name_length = readWORDTag(io_) * 2)
xmpData()[codec + std::string(".CodecName")] = readStringWcharTag(io_, codec_name_length);
- uint16_t codec_desc_length = readWORDTag(io_);
- if (codec_desc_length)
+ if (uint16_t codec_desc_length = readWORDTag(io_))
xmpData()[codec + std::string(".CodecDescription")] = readStringWcharTag(io_, codec_desc_length);
uint16_t codec_info_length = readWORDTag(io_);
@@ -422,13 +420,11 @@ void AsfVideo::extendedContentDescription() {
std::string value;
for (uint16_t i = 0; i < content_descriptor_count; i++) {
- uint16_t descriptor_name_length = readWORDTag(io_);
- if (descriptor_name_length)
+ if (uint16_t descriptor_name_length = readWORDTag(io_))
value += readStringWcharTag(io_, descriptor_name_length); // Descriptor Name
uint16_t descriptor_value_data_type = readWORDTag(io_);
- uint16_t descriptor_value_length = readWORDTag(io_);
- if (descriptor_value_length) {
+ if (uint16_t descriptor_value_length = readWORDTag(io_)) {
// Descriptor Value
switch (descriptor_value_data_type) {
case 0 /*Unicode string */:
@@ -448,7 +444,6 @@ void AsfVideo::extendedContentDescription() {
break;
case 5 /*WORD*/:
value += std::string(": ") + std::to_string(readWORDTag(io_));
- ;
break;
}
}
diff --git a/src/basicio.cpp b/src/basicio.cpp
index b0760b8e..6909193e 100644
--- a/src/basicio.cpp
+++ b/src/basicio.cpp
@@ -159,7 +159,11 @@ int FileIo::Impl::switchMode(OpMode opMode) {
}
// Reopen the file
- long offset = std::ftell(fp_);
+#ifdef _WIN32
+ auto offset = _ftelli64(fp_);
+#else
+ auto offset = ftello(fp_);
+#endif
if (offset == -1)
return -1;
// 'Manual' open("r+b") to avoid munmap()
@@ -172,7 +176,11 @@ int FileIo::Impl::switchMode(OpMode opMode) {
fp_ = std::fopen(path_.c_str(), openMode_.c_str());
if (!fp_)
return 1;
- return std::fseek(fp_, offset, SEEK_SET);
+#ifdef _WIN32
+ return _fseeki64(fp_, offset, SEEK_SET);
+#else
+ return fseeko(fp_, offset, SEEK_SET);
+#endif
} // FileIo::Impl::switchMode
int FileIo::Impl::stat(StructStat& buf) const {
@@ -460,15 +468,19 @@ int FileIo::seek(int64_t offset, Position pos) {
if (p_->switchMode(Impl::opSeek) != 0)
return 1;
-#ifdef _WIN64
+#ifdef _WIN32
return _fseeki64(p_->fp_, offset, fileSeek);
#else
- return std::fseek(p_->fp_, static_cast(offset), fileSeek);
+ return fseeko(p_->fp_, offset, fileSeek);
#endif
}
size_t FileIo::tell() const {
- const long pos = std::ftell(p_->fp_);
+#ifdef _WIN32
+ auto pos = _ftelli64(p_->fp_);
+#else
+ auto pos = ftello(p_->fp_);
+#endif
Internal::enforce(pos >= 0, ErrorCode::kerInputDataReadFailed);
return static_cast(pos);
}
@@ -1069,7 +1081,8 @@ size_t RemoteIo::Impl::populateBlocks(size_t lowBlock, size_t highBlock) {
throw Error(ErrorCode::kerErrorMessage, "Data By Range is empty. Please check the permission.");
}
auto source = reinterpret_cast(const_cast(data.c_str()));
- size_t remain = rcount, totalRead = 0;
+ size_t remain = rcount;
+ size_t totalRead = 0;
size_t iBlock = (rcount == size_) ? 0 : lowBlock;
while (remain) {
@@ -1109,7 +1122,9 @@ int RemoteIo::open() {
p_->blocksMap_ = new BlockMap[nBlocks];
p_->isMalloced_ = true;
auto source = reinterpret_cast(const_cast(data.c_str()));
- size_t remain = p_->size_, iBlock = 0, totalRead = 0;
+ size_t remain = p_->size_;
+ size_t iBlock = 0;
+ size_t totalRead = 0;
while (remain) {
auto allow = std::min(remain, p_->blockSize_);
p_->blocksMap_[iBlock].populate(&source[totalRead], allow);
@@ -1465,8 +1480,7 @@ void HttpIo::HttpImpl::writeRemote(const byte* data, size_t size, size_t from, s
}
// standardize the path without "/" at the beginning.
- std::size_t protocolIndex = scriptPath.find("://");
- if (protocolIndex == std::string::npos && scriptPath.front() != '/') {
+ if (scriptPath.find("://") == std::string::npos && scriptPath.front() != '/') {
scriptPath = "/" + scriptPath;
}
@@ -1651,8 +1665,7 @@ void CurlIo::CurlImpl::writeRemote(const byte* data, size_t size, size_t from, s
Exiv2::Uri hostInfo = Exiv2::Uri::Parse(path_);
// add the protocol and host to the path
- std::size_t protocolIndex = scriptPath.find("://");
- if (protocolIndex == std::string::npos) {
+ if (scriptPath.find("://") == std::string::npos) {
if (scriptPath.front() != '/')
scriptPath = "/" + scriptPath;
scriptPath = hostInfo.Protocol + "://" + hostInfo.Host + scriptPath;
diff --git a/src/bmffimage.cpp b/src/bmffimage.cpp
index 159fd161..a0b5471e 100644
--- a/src/bmffimage.cpp
+++ b/src/bmffimage.cpp
@@ -137,18 +137,16 @@ std::string BmffImage::mimeType() const {
uint32_t BmffImage::pixelWidth() const {
auto imageWidth = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelXDimension"));
- if (imageWidth != exifData_.end() && imageWidth->count() > 0) {
- return imageWidth->toUint32();
- }
- return pixelWidth_;
+ if (imageWidth == exifData_.end() || imageWidth->count() == 0)
+ return pixelWidth_;
+ return imageWidth->toUint32();
}
uint32_t BmffImage::pixelHeight() const {
auto imageHeight = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelYDimension"));
- if (imageHeight != exifData_.end() && imageHeight->count() > 0) {
- return imageHeight->toUint32();
- }
- return pixelHeight_;
+ if (imageHeight == exifData_.end() || imageHeight->count() == 0)
+ return pixelHeight_;
+ return imageHeight->toUint32();
}
std::string BmffImage::uuidName(const Exiv2::DataBuf& uuid) {
@@ -254,13 +252,13 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
size_t hdrsize = sizeof(hdrbuf);
Internal::enforce(hdrsize <= static_cast(pbox_end - address), Exiv2::ErrorCode::kerCorruptedMetadata);
- if (io_->read(reinterpret_cast(&hdrbuf), sizeof(hdrbuf)) != sizeof(hdrbuf))
+ if (io_->read(hdrbuf, sizeof(hdrbuf)) != sizeof(hdrbuf))
return pbox_end;
// The box length is encoded as a uint32_t by default, but the special value 1 means
// that it's a uint64_t.
- uint64_t box_length = getULong(reinterpret_cast(&hdrbuf[0]), endian_);
- uint32_t box_type = getULong(reinterpret_cast(&hdrbuf[sizeof(uint32_t)]), endian_);
+ uint64_t box_length = getULong(&hdrbuf[0], endian_);
+ uint32_t box_type = getULong(&hdrbuf[sizeof(uint32_t)], endian_);
bool bLF = true;
if (bTrace) {
diff --git a/src/convert.cpp b/src/convert.cpp
index 8a9f7b47..8c54e86c 100644
--- a/src/convert.cpp
+++ b/src/convert.cpp
@@ -274,8 +274,8 @@ class Converter {
// DATA
static const Conversion conversion_[]; //(datetime.year),
- static_cast(datetime.month), static_cast(datetime.day), static_cast(datetime.hour),
- static_cast(datetime.minute), static_cast(datetime.second));
+ snprintf(buf, sizeof(buf), "%4d:%02d:%02d %02d:%02d:%02d", datetime.year, datetime.month, datetime.day,
+ datetime.hour, datetime.minute, datetime.second);
buf[sizeof(buf) - 1] = 0;
(*exifData_)[to] = buf;
@@ -978,8 +972,7 @@ void Converter::cnvXmpDate(const char* from, const char* to) {
(*exifData_)[to] = array.str();
prepareExifTarget("Exif.GPSInfo.GPSDateStamp", true);
- snprintf(buf, sizeof(buf), "%4d:%02d:%02d", static_cast(datetime.year), static_cast(datetime.month),
- static_cast(datetime.day));
+ snprintf(buf, sizeof(buf), "%4d:%02d:%02d", datetime.year, datetime.month, datetime.day);
buf[sizeof(buf) - 1] = 0;
(*exifData_)["Exif.GPSInfo.GPSDateStamp"] = buf;
}
diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp
index 8917df46..7006deea 100644
--- a/src/crwimage_int.cpp
+++ b/src/crwimage_int.cpp
@@ -22,7 +22,7 @@ class RotationMap {
private:
//! Helper structure for the mapping list
- using OmList = struct {
+ struct OmList {
uint16_t orientation;
int32_t degrees;
};
diff --git a/src/crwimage_int.hpp b/src/crwimage_int.hpp
index 69cca602..6f55be6d 100644
--- a/src/crwimage_int.hpp
+++ b/src/crwimage_int.hpp
@@ -20,7 +20,7 @@ namespace Exiv2::Internal {
class CiffHeader;
class CiffComponent;
struct CrwMapping;
-using CrwSubDir = struct {
+struct CrwSubDir {
uint16_t dir;
uint16_t parent;
};
@@ -287,19 +287,7 @@ class CiffComponent {
a CRW (Canon Raw data) image.
*/
class CiffEntry : public CiffComponent {
- public:
- //! @name Creators
- //@{
- //! Default constructor
- CiffEntry() = default;
- //! Constructor taking a tag and directory
- CiffEntry(uint16_t tag, uint16_t dir) : CiffComponent(tag, dir) {
- }
- //@}
-
- // Default assignment operator is fine
-
- private:
+ using CiffComponent::CiffComponent;
//! @name Manipulators
//@{
using CiffComponent::doAdd;
@@ -322,15 +310,11 @@ class CiffEntry : public CiffComponent {
//! This class models a CIFF directory of a CRW (Canon Raw data) image.
class CiffDirectory : public CiffComponent {
+ using CiffComponent::CiffComponent;
+
public:
//! @name Creators
//@{
- //! Default constructor
- CiffDirectory() = default;
- //! Constructor taking a tag and directory
- CiffDirectory(uint16_t tag, uint16_t dir) : CiffComponent(tag, dir) {
- }
-
//! Virtual destructor
~CiffDirectory() override;
//@}
diff --git a/src/exif.cpp b/src/exif.cpp
index 81832746..43b005b6 100644
--- a/src/exif.cpp
+++ b/src/exif.cpp
@@ -609,8 +609,7 @@ WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteO
switch (ptt) {
case pttLen: {
delTags = false;
- auto pos = ed.findKey(ExifKey(key));
- if (pos != ed.end() && sumToLong(*pos) > 32768) {
+ if (auto pos = ed.findKey(ExifKey(key)); pos != ed.end() && sumToLong(*pos) > 32768) {
delTags = true;
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Exif tag " << pos->key() << " not encoded\n";
@@ -621,8 +620,7 @@ WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteO
}
case pttTag: {
if (delTags) {
- auto pos = ed.findKey(ExifKey(key));
- if (pos != ed.end()) {
+ if (auto pos = ed.findKey(ExifKey(key)); pos != ed.end()) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Exif tag " << pos->key() << " not encoded\n";
#endif
diff --git a/src/futils.cpp b/src/futils.cpp
index 0dca8352..3e30c999 100644
--- a/src/futils.cpp
+++ b/src/futils.cpp
@@ -105,7 +105,8 @@ std::string urlencode(const std::string& str) {
}
void urldecode(std::string& str) {
- size_t idxIn{0}, idxOut{0};
+ size_t idxIn{0};
+ size_t idxOut{0};
size_t sizeStr = str.size();
while (idxIn < sizeStr) {
if (str[idxIn] == '%') {
@@ -234,9 +235,8 @@ std::string strError() {
#ifdef EXV_HAVE_STRERROR_R
const size_t n = 1024;
#ifdef EXV_STRERROR_R_CHAR_P
- char* buf = nullptr;
char buf2[n] = {};
- buf = strerror_r(error, buf2, n);
+ auto buf = strerror_r(error, buf2, n);
#else
char buf[n] = {};
const int ret = strerror_r(error, buf, n);
diff --git a/src/helper_functions.cpp b/src/helper_functions.cpp
index 7bb8bb47..609cd5cb 100644
--- a/src/helper_functions.cpp
+++ b/src/helper_functions.cpp
@@ -28,25 +28,25 @@ std::string utf16ToUtf8(const std::wstring& wstr) {
return str;
}
-uint64_t readQWORDTag(BasicIo::UniquePtr& io) {
+uint64_t readQWORDTag(const BasicIo::UniquePtr& io) {
Internal::enforce(QWORD <= io->size() - io->tell(), Exiv2::ErrorCode::kerCorruptedMetadata);
DataBuf FieldBuf = io->read(QWORD);
return FieldBuf.read_uint64(0, littleEndian);
}
-uint32_t readDWORDTag(BasicIo::UniquePtr& io) {
+uint32_t readDWORDTag(const BasicIo::UniquePtr& io) {
Internal::enforce(DWORD <= io->size() - io->tell(), Exiv2::ErrorCode::kerCorruptedMetadata);
DataBuf FieldBuf = io->read(DWORD);
return FieldBuf.read_uint32(0, littleEndian);
}
-uint16_t readWORDTag(BasicIo::UniquePtr& io) {
+uint16_t readWORDTag(const BasicIo::UniquePtr& io) {
Internal::enforce(WORD <= io->size() - io->tell(), Exiv2::ErrorCode::kerCorruptedMetadata);
DataBuf FieldBuf = io->read(WORD);
return FieldBuf.read_uint16(0, littleEndian);
}
-std::string readStringWcharTag(BasicIo::UniquePtr& io, size_t length) {
+std::string readStringWcharTag(const BasicIo::UniquePtr& io, size_t length) {
Internal::enforce(length <= io->size() - io->tell(), Exiv2::ErrorCode::kerCorruptedMetadata);
DataBuf FieldBuf(length + 1);
io->readOrThrow(FieldBuf.data(), length, ErrorCode::kerFailedToReadImageData);
@@ -54,7 +54,7 @@ std::string readStringWcharTag(BasicIo::UniquePtr& io, size_t length) {
return utf16ToUtf8(wst);
}
-std::string readStringTag(BasicIo::UniquePtr& io, size_t length) {
+std::string readStringTag(const BasicIo::UniquePtr& io, size_t length) {
Internal::enforce(length <= io->size() - io->tell(), Exiv2::ErrorCode::kerCorruptedMetadata);
DataBuf FieldBuf(length + 1);
io->readOrThrow(FieldBuf.data(), length, ErrorCode::kerFailedToReadImageData);
diff --git a/src/helper_functions.hpp b/src/helper_functions.hpp
index 23f564d4..a9fffa95 100644
--- a/src/helper_functions.hpp
+++ b/src/helper_functions.hpp
@@ -43,15 +43,15 @@ static constexpr size_t GUID = 0x10;
*/
std::string utf16ToUtf8(const std::wstring& wstr);
-[[nodiscard]] uint64_t readQWORDTag(Exiv2::BasicIo::UniquePtr& io);
+[[nodiscard]] uint64_t readQWORDTag(const Exiv2::BasicIo::UniquePtr& io);
-[[nodiscard]] uint32_t readDWORDTag(Exiv2::BasicIo::UniquePtr& io);
+[[nodiscard]] uint32_t readDWORDTag(const Exiv2::BasicIo::UniquePtr& io);
-[[nodiscard]] uint16_t readWORDTag(Exiv2::BasicIo::UniquePtr& io);
+[[nodiscard]] uint16_t readWORDTag(const Exiv2::BasicIo::UniquePtr& io);
-[[nodiscard]] std::string readStringWcharTag(Exiv2::BasicIo::UniquePtr& io, size_t length);
+[[nodiscard]] std::string readStringWcharTag(const Exiv2::BasicIo::UniquePtr& io, size_t length);
-[[nodiscard]] std::string readStringTag(Exiv2::BasicIo::UniquePtr& io, size_t length = DWORD);
+[[nodiscard]] std::string readStringTag(const Exiv2::BasicIo::UniquePtr& io, size_t length = DWORD);
/*!
@brief Calculates Aspect Ratio of a video
diff --git a/src/http.cpp b/src/http.cpp
index 7197a30b..2ef670b0 100644
--- a/src/http.cpp
+++ b/src/http.cpp
@@ -76,9 +76,7 @@ static int forgive(int n, int& err) {
if (n == 0)
return FINISH; // server hungup
#endif
- bool bForgive = err == WSAEWOULDBLOCK || err == WSAENOTCONN;
- bool bError = n == SOCKET_ERROR;
- if (bError && bForgive)
+ if (n == SOCKET_ERROR && (err == WSAEWOULDBLOCK || err == WSAENOTCONN))
return 0;
return n;
}
diff --git a/src/iptc.cpp b/src/iptc.cpp
index 72e423e4..672747c1 100644
--- a/src/iptc.cpp
+++ b/src/iptc.cpp
@@ -231,7 +231,7 @@ size_t IptcData::size() const {
return newSize;
}
-int IptcData::add(const IptcKey& key, Value* value) {
+int IptcData::add(const IptcKey& key, const Value* value) {
return add(Iptcdatum(key, value));
}
@@ -439,8 +439,7 @@ DataBuf IptcParser::encode(const IptcData& iptcData) {
*pWrite++ = static_cast(iter.tag());
// extended or standard dataset?
- size_t dataSize = iter.size();
- if (dataSize > 32767) {
+ if (size_t dataSize = iter.size(); dataSize > 32767) {
// always use 4 bytes for extended length
uint16_t sizeOfSize = 4 | 0x8000;
us2Data(pWrite, sizeOfSize, bigEndian);
diff --git a/src/jp2image.cpp b/src/jp2image.cpp
index b721c0d7..fb9fc786 100644
--- a/src/jp2image.cpp
+++ b/src/jp2image.cpp
@@ -353,8 +353,7 @@ void Jp2Image::readMetadata() {
throw Error(ErrorCode::kerInputDataReadFailed);
xmpPacket_.assign(rawData.c_str(), rawData.size());
- std::string::size_type idx = xmpPacket_.find_first_of('<');
- if (idx != std::string::npos && idx > 0) {
+ if (auto idx = xmpPacket_.find_first_of('<'); idx != std::string::npos && idx > 0) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Removing " << static_cast(idx)
<< " characters from the beginning of the XMP packet" << std::endl;
diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp
index f30610ee..75f5ae72 100644
--- a/src/jpgimage.cpp
+++ b/src/jpgimage.cpp
@@ -719,8 +719,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
}
const byte* pExifData = rawExif.c_data();
size_t exifSize = rawExif.size();
- WriteMethod wm = ExifParser::encode(blob, pExifData, exifSize, bo, exifData_);
- if (wm == wmIntrusive) {
+ if (ExifParser::encode(blob, pExifData, exifSize, bo, exifData_) == wmIntrusive) {
pExifData = !blob.empty() ? blob.data() : nullptr;
exifSize = blob.size();
}
diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp
index 9943221e..43a59ca9 100644
--- a/src/makernote_int.cpp
+++ b/src/makernote_int.cpp
@@ -150,8 +150,7 @@ TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, const std::strin
} // TiffMnCreator::create
TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, IfdId mnGroup) {
- auto tmr = Exiv2::find(registry_, mnGroup);
- if (tmr) {
+ if (auto tmr = Exiv2::find(registry_, mnGroup)) {
if (tmr->newMnFct2_) {
return tmr->newMnFct2_(tag, group, mnGroup);
}
@@ -1055,7 +1054,7 @@ const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, const ui
std::string getExifModel(Exiv2::Internal::TiffComponent* pRoot) {
// Lookup the Exif.Image.Model tag
const auto value = getExifValue(pRoot, 0x0110, Exiv2::IfdId::ifd0Id);
- return (!value || value->count() == 0) ? std::string("") : static_cast(value->toString());
+ return (!value || value->count() == 0) ? std::string() : value->toString();
}
void ncrypt(Exiv2::byte* pData, uint32_t size, uint32_t count, uint32_t serial) {
diff --git a/src/minoltamn_int.cpp b/src/minoltamn_int.cpp
index 69650696..45596b31 100644
--- a/src/minoltamn_int.cpp
+++ b/src/minoltamn_int.cpp
@@ -1465,7 +1465,8 @@ static std::string& trim(std::string& s, const char* t = " \t\n\r\f\v") {
// https://stackoverflow.com/questions/14265581/parse-split-a-string-in-c-using-string-delimiter-standard-c
static std::vector split(const std::string& str, const std::string& delim) {
std::vector tokens;
- size_t prev = 0, pos = 0;
+ size_t prev = 0;
+ size_t pos = 0;
do {
pos = str.find(delim, prev);
if (pos == std::string::npos)
diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp
index 05505a5a..caf84530 100644
--- a/src/nikonmn_int.cpp
+++ b/src/nikonmn_int.cpp
@@ -3809,12 +3809,11 @@ std::ostream& Nikon3MakerNote::printLensId4ZMount(std::ostream& os, const Value&
}
// from https://github.com/exiftool/exiftool/blob/12.44/lib/Image/ExifTool/Nikon.pm#L4969
- using lens = struct {
+ static constexpr struct lens {
uint16_t l;
const char* vendor;
const char* name;
- };
- static constexpr lens zmountlens[] = {
+ } zmountlens[] = {
{1, "Nikon", "Nikkor Z 24-70mm f/4 S"},
{2, "Nikon", "Nikkor Z 14-30mm f/4 S"},
{4, "Nikon", "Nikkor Z 35mm f/1.8 S"},
diff --git a/src/olympusmn_int.cpp b/src/olympusmn_int.cpp
index daee3ba6..ea0f6004 100644
--- a/src/olympusmn_int.cpp
+++ b/src/olympusmn_int.cpp
@@ -1426,7 +1426,7 @@ std::ostream& OlympusMakerNote::printEq0x0301(std::ostream& os, const Value& val
//! OlympusCs FocusMode, tag 0x0301
// (1 or 2 values)
std::ostream& OlympusMakerNote::printCs0x0301(std::ostream& os, const Value& value, const ExifData*) {
- using mode = struct {
+ struct mode {
uint16_t tag;
const char* name;
};
@@ -1538,20 +1538,18 @@ std::ostream& OlympusMakerNote::print0x0305(std::ostream& os, const Value& value
// Olympus FocusInfo tag 0x0308 AFPoint
std::ostream& OlympusMakerNote::print0x0308(std::ostream& os, const Value& value, const ExifData* metadata) {
- using point = struct {
+ static constexpr struct point {
uint16_t p;
const char* name;
- };
- static constexpr point afPoints[] = {
+ } afPoints[] = {
{0, N_("Left (or n/a)")}, {1, N_("Center (horizontal)")}, {2, N_("Right")}, {3, N_("Center (vertical)")},
{255, N_("None")},
};
- using pointE3 = struct {
+ static constexpr struct pointE3 {
byte p;
const char* name;
- };
- static constexpr pointE3 afPointsE3[] = {
+ } afPointsE3[] = {
{0x00, N_("None")},
{0x01, N_("Top-left (horizontal)")},
{0x02, N_("Top-center (horizontal)")},
diff --git a/src/pentaxmn_int.cpp b/src/pentaxmn_int.cpp
index 1dce5a23..743ccc07 100644
--- a/src/pentaxmn_int.cpp
+++ b/src/pentaxmn_int.cpp
@@ -964,9 +964,7 @@ std::ostream& PentaxMakerNote::printFlashCompensation(std::ostream& os, const Va
}
std::ostream& PentaxMakerNote::printBracketing(std::ostream& os, const Value& value, const ExifData*) {
- const auto l0 = value.toUint32(0);
-
- if (l0 < 10) {
+ if (auto l0 = value.toUint32(0); l0 < 10) {
os << std::setprecision(2) << static_cast(l0) / 3 << " EV";
} else {
os << std::setprecision(2) << static_cast(l0) - 9.5F << " EV";
diff --git a/src/pentaxmn_int.hpp b/src/pentaxmn_int.hpp
index 94f11498..567355a7 100644
--- a/src/pentaxmn_int.hpp
+++ b/src/pentaxmn_int.hpp
@@ -70,8 +70,7 @@ std::ostream& printCombiTag(std::ostream& os, const Value& value, const ExifData
}
l += (value.toUint32(c) << ((count - c - 1) * 8));
}
- auto td = Exiv2::find(array, l);
- if (td) {
+ if (auto td = Exiv2::find(array, l)) {
os << exvGettext(td->label_);
} else {
os << exvGettext("Unknown") << " (0x" << std::setw(2 * count) << std::setfill('0') << std::hex << l << std::dec
diff --git a/src/pgfimage.cpp b/src/pgfimage.cpp
index 8c62d3b6..6ce21ac9 100644
--- a/src/pgfimage.cpp
+++ b/src/pgfimage.cpp
@@ -149,7 +149,8 @@ void PgfImage::doWriteMetadata(BasicIo& outIo) {
readPgfHeaderSize(*io_);
- uint32_t w = 0, h = 0;
+ uint32_t w = 0;
+ uint32_t h = 0;
DataBuf header = readPgfHeaderStructure(*io_, w, h);
auto img = ImageFactory::create(ImageType::png);
@@ -268,9 +269,8 @@ DataBuf PgfImage::readPgfHeaderStructure(BasicIo& iIo, uint32_t& width, uint32_t
byte bpp = buffer.pData_[10];
byte channels = buffer.pData_[11];
*/
- byte mode = header.read_uint8(12);
- if (mode == 2) // Indexed color image. We pass color table (256 * 3 bytes).
+ if (header.read_uint8(12) == 2) // Indexed color image. We pass color table (256 * 3 bytes).
{
header.alloc(16 + 256 * 3);
diff --git a/src/photoshop.cpp b/src/photoshop.cpp
index 367b74ec..f05f3682 100644
--- a/src/photoshop.cpp
+++ b/src/photoshop.cpp
@@ -136,8 +136,7 @@ DataBuf Photoshop::setIptcIrb(const byte* pPsData, size_t sizePsData, const Iptc
}
// Write new iptc record if we have it
- DataBuf rawIptc = IptcParser::encode(iptcData);
- if (!rawIptc.empty()) {
+ if (DataBuf rawIptc = IptcParser::encode(iptcData); !rawIptc.empty()) {
std::array tmpBuf;
std::copy_n(Photoshop::irbId_.front(), 4, tmpBuf.data());
us2Data(tmpBuf.data() + 4, iptc_, bigEndian);
diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp
index 183d1b27..697a30c6 100644
--- a/src/pngchunk_int.cpp
+++ b/src/pngchunk_int.cpp
@@ -91,8 +91,7 @@ DataBuf PngChunk::parseTXTChunk(const DataBuf& data, size_t keysize, TxtChunkTyp
// Extract a deflate compressed Latin-1 text chunk
// we get the compression method after the key
- const byte* compressionMethod = data.c_data(keysize + 1);
- if (*compressionMethod != 0x00) {
+ if (*data.c_data(keysize + 1) != 0x00) {
// then it isn't zlib compressed and we are sunk
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngChunk::parseTXTChunk: Non-standard zTXt compression method.\n";
@@ -271,8 +270,7 @@ void PngChunk::parseChunkContent(Image* pImage, const byte* key, size_t keySize,
if (length > 0) {
std::string& xmpPacket = pImage->xmpPacket();
xmpPacket.assign(xmpBuf.c_str(), length);
- std::string::size_type idx = xmpPacket.find_first_of('<');
- if (idx != std::string::npos && idx > 0) {
+ if (auto idx = xmpPacket.find_first_of('<'); idx != std::string::npos && idx > 0) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Removing " << idx << " characters from the beginning of the XMP packet\n";
#endif
@@ -291,8 +289,7 @@ void PngChunk::parseChunkContent(Image* pImage, const byte* key, size_t keySize,
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) {
+ if (auto idx = xmpPacket.find_first_of('<'); idx != std::string::npos && idx > 0) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Removing " << idx << " characters "
<< "from the beginning of the XMP packet\n";
diff --git a/src/pngimage.cpp b/src/pngimage.cpp
index 4f7bd6ea..3d62373e 100644
--- a/src/pngimage.cpp
+++ b/src/pngimage.cpp
@@ -408,8 +408,7 @@ void PngImage::readMetadata() {
// Decode chunk data length.
uint32_t chunkLength = cheaderBuf.read_uint32(0, Exiv2::bigEndian);
- const size_t pos = io_->tell();
- if (chunkLength > imgSize - pos) {
+ if (chunkLength > imgSize - io_->tell()) {
throw Exiv2::Error(ErrorCode::kerFailedToReadImageData);
}
diff --git a/src/preview.cpp b/src/preview.cpp
index ea121f14..18fe6122 100644
--- a/src/preview.cpp
+++ b/src/preview.cpp
@@ -342,12 +342,7 @@ Loader::Loader(PreviewId id, const Image& image) : id_(id), image_(image) {
}
PreviewProperties Loader::getProperties() const {
- PreviewProperties prop;
- prop.id_ = id_;
- prop.size_ = size_;
- prop.width_ = width_;
- prop.height_ = height_;
- return prop;
+ return {"", "", size_, width_, height_, id_};
}
PreviewId Loader::getNumLoaders() {
@@ -548,8 +543,7 @@ bool LoaderExifJpeg::readDimensions() {
LoaderExifDataJpeg::LoaderExifDataJpeg(PreviewId id, const Image& image, int parIdx) :
Loader(id, image), dataKey_(param_[parIdx].dataKey_) {
- auto pos = image_.exifData().findKey(dataKey_);
- if (pos != image_.exifData().end()) {
+ if (auto pos = image_.exifData().findKey(dataKey_); pos != image_.exifData().end()) {
size_ = pos->sizeDataArea(); // indirect data
if (size_ == 0 && pos->typeId() == undefined)
size_ = pos->size(); // direct data
@@ -576,8 +570,7 @@ DataBuf LoaderExifDataJpeg::getData() const {
if (!valid())
return {};
- auto pos = image_.exifData().findKey(dataKey_);
- if (pos != image_.exifData().end()) {
+ if (auto pos = image_.exifData().findKey(dataKey_); pos != image_.exifData().end()) {
DataBuf buf = pos->dataArea(); // indirect data
if (buf.empty()) { // direct data
@@ -706,7 +699,7 @@ DataBuf LoaderTiff::getData() const {
}
}
- Value& dataValue = const_cast(preview["Exif.Image." + offsetTag_].value());
+ auto& dataValue = const_cast(preview["Exif.Image." + offsetTag_].value());
if (dataValue.sizeDataArea() == 0) {
// image data are not available via exifData, read them from image_.io()
@@ -868,7 +861,7 @@ DataBuf decodeBase64(const std::string& src) {
// calculate dest size
auto validSrcSize = static_cast(
- std::count_if(src.begin(), src.end(), [=](unsigned char c) { return decodeBase64Table.at(c) != invalid; }));
+ std::count_if(src.begin(), src.end(), [&](unsigned char c) { return decodeBase64Table.at(c) != invalid; }));
if (validSrcSize > ULONG_MAX / 3)
return {}; // avoid integer overflow
const unsigned long destSize = (validSrcSize * 3) / 4;
@@ -936,8 +929,7 @@ DataBuf decodeAi7Thumbnail(const DataBuf& src) {
}
DataBuf makePnm(size_t width, size_t height, const DataBuf& rgb) {
- const size_t expectedSize = width * height * 3UL;
- if (rgb.size() != expectedSize) {
+ if (size_t expectedSize = width * height * 3UL; rgb.size() != expectedSize) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Invalid size of preview data. Expected " << expectedSize << " bytes, got " << rgb.size()
<< " bytes.\n";
diff --git a/src/properties.cpp b/src/properties.cpp
index a7c414d9..8bdc2b1d 100644
--- a/src/properties.cpp
+++ b/src/properties.cpp
@@ -4939,8 +4939,7 @@ void XmpProperties::registerNs(const std::string& ns, const std::string& prefix)
if (ns2.back() != '/' && ns2.back() != '#')
ns2 += '/';
// Check if there is already a registered namespace with this prefix
- const XmpNsInfo* xnp = lookupNsRegistryUnsafe(XmpNsInfo::Prefix{prefix});
- if (xnp) {
+ if (auto xnp = lookupNsRegistryUnsafe(XmpNsInfo::Prefix{prefix})) {
#ifndef SUPPRESS_WARNINGS
if (ns2 != xnp->ns_)
EXV_WARNING << "Updating namespace URI for " << prefix << " from " << xnp->ns_ << " to " << ns2 << "\n";
@@ -5006,8 +5005,7 @@ std::string XmpProperties::prefix(const std::string& ns) {
std::string XmpProperties::ns(const std::string& prefix) {
auto scoped_read_lock = std::scoped_lock(mutex_);
- const XmpNsInfo* xn = lookupNsRegistryUnsafe(XmpNsInfo::Prefix{prefix});
- if (xn)
+ if (auto xn = lookupNsRegistryUnsafe(XmpNsInfo::Prefix{prefix}))
return xn->ns_;
return nsInfoUnsafe(prefix)->ns_;
}
@@ -5031,8 +5029,7 @@ const XmpPropertyInfo* XmpProperties::propertyInfo(const XmpKey& key) {
std::string prefix = key.groupName();
std::string property = key.tagName();
// If property is a path for a nested property, determines the innermost element
- std::string::size_type i = property.find_last_of('/');
- if (i != std::string::npos) {
+ if (auto i = property.find_last_of('/'); i != std::string::npos) {
for (; i != std::string::npos && !isalpha(property.at(i)); ++i) {
}
property = property.substr(i);
@@ -5212,8 +5209,7 @@ void XmpKey::Impl::decomposeKey(const std::string& key) {
std::string::size_type pos1 = key.find('.');
if (pos1 == std::string::npos)
throw Error(ErrorCode::kerInvalidKey, key);
- std::string familyName = key.substr(0, pos1);
- if (familyName != familyName_)
+ if (key.substr(0, pos1) != familyName_)
throw Error(ErrorCode::kerInvalidKey, key);
std::string::size_type pos0 = pos1 + 1;
pos1 = key.find('.', pos0);
diff --git a/src/psdimage.cpp b/src/psdimage.cpp
index 3ac075f4..fb5431a0 100644
--- a/src/psdimage.cpp
+++ b/src/psdimage.cpp
@@ -157,8 +157,7 @@ void PsdImage::readMetadata() {
}
// skip it
- uint32_t colorDataLength = getULong(buf, bigEndian);
- if (io_->seek(colorDataLength, BasicIo::cur)) {
+ if (io_->seek(getULong(buf, bigEndian), BasicIo::cur)) {
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
}
@@ -547,7 +546,7 @@ uint32_t PsdImage::writeIptcData(const IptcData& iptcData, BasicIo& out) {
uint32_t resLength = 0;
byte buf[8];
- if (iptcData.count() > 0) {
+ if (!iptcData.empty()) {
DataBuf rawIptc = IptcParser::encode(iptcData);
if (!rawIptc.empty()) {
#ifdef EXIV2_DEBUG_MESSAGES
diff --git a/src/quicktimevideo.cpp b/src/quicktimevideo.cpp
index 26efa717..0e4c87a0 100644
--- a/src/quicktimevideo.cpp
+++ b/src/quicktimevideo.cpp
@@ -599,11 +599,9 @@ void QuickTimeVideo::decodeBlock(std::string const& entered_from) {
hdrsize += 8;
io_->readOrThrow(data.data(), data.size());
size = data.read_uint64(0, bigEndian);
- } else if (size == 0) {
- if (entered_from == "meta") {
- size = buf.read_uint32(0, bigEndian);
- io_->readOrThrow(buf.data(), 4, Exiv2::ErrorCode::kerCorruptedMetadata);
- }
+ } else if (size == 0 && entered_from == "meta") {
+ size = buf.read_uint32(0, bigEndian);
+ io_->readOrThrow(buf.data(), 4, Exiv2::ErrorCode::kerCorruptedMetadata);
}
enforce(size >= hdrsize, Exiv2::ErrorCode::kerCorruptedMetadata);
@@ -745,7 +743,8 @@ void QuickTimeVideo::keysTagDecoder(size_t size) {
} // QuickTimeVideo::keysTagDecoder
void QuickTimeVideo::trackApertureTagDecoder(size_t size) {
- DataBuf buf(4), buf2(2);
+ DataBuf buf(4);
+ DataBuf buf2(2);
size_t cur_pos = io_->tell();
byte n = 3;
@@ -794,7 +793,8 @@ void QuickTimeVideo::trackApertureTagDecoder(size_t size) {
void QuickTimeVideo::CameraTagsDecoder(size_t size_external) {
size_t cur_pos = io_->tell();
- DataBuf buf(50), buf2(4);
+ DataBuf buf(50);
+ DataBuf buf2(4);
const TagDetails* td;
io_->readOrThrow(buf.data(), 4);
@@ -839,7 +839,8 @@ void QuickTimeVideo::CameraTagsDecoder(size_t size_external) {
void QuickTimeVideo::userDataDecoder(size_t size_external) {
size_t cur_pos = io_->tell();
const TagVocabulary* td;
- const TagVocabulary *tv, *tv_internal;
+ const TagVocabulary* tv;
+ const TagVocabulary* tv_internal;
const long bufMinSize = 100;
DataBuf buf(bufMinSize);
@@ -905,10 +906,13 @@ void QuickTimeVideo::userDataDecoder(size_t size_external) {
void QuickTimeVideo::NikonTagsDecoder(size_t size_external) {
size_t cur_pos = io_->tell();
- DataBuf buf(200), buf2(4 + 1);
+ DataBuf buf(200);
+ DataBuf buf2(4 + 1);
uint32_t TagID = 0;
- uint16_t dataLength = 0, dataType = 2;
- const TagDetails *td, *td2;
+ uint16_t dataLength = 0;
+ uint16_t dataType = 2;
+ const TagDetails* td;
+ const TagDetails* td2;
for (int i = 0; i < 100; i++) {
io_->readOrThrow(buf.data(), 4);
@@ -1140,7 +1144,8 @@ void QuickTimeVideo::timeToSampleDecoder() {
DataBuf buf(4 + 1);
io_->readOrThrow(buf.data(), 4);
io_->readOrThrow(buf.data(), 4);
- uint64_t totalframes = 0, timeOfFrames = 0;
+ uint64_t totalframes = 0;
+ uint64_t timeOfFrames = 0;
const uint32_t noOfEntries = buf.read_uint32(0, bigEndian);
for (uint32_t i = 0; i < noOfEntries; i++) {
@@ -1604,8 +1609,7 @@ bool isQTimeType(BasicIo& iIo, bool advance) {
// we only match if we actually know the video type. This is done
// to avoid matching just on ftyp because bmffimage also has that
// header.
- auto td = Exiv2::find(qTimeFileType, std::string{buf.c_str(8), 4});
- if (td) {
+ if (Exiv2::find(qTimeFileType, std::string{buf.c_str(8), 4})) {
matched = true;
}
break;
diff --git a/src/rafimage.cpp b/src/rafimage.cpp
index 1180344e..0fcd7e11 100644
--- a/src/rafimage.cpp
+++ b/src/rafimage.cpp
@@ -28,18 +28,16 @@ std::string RafImage::mimeType() const {
uint32_t RafImage::pixelWidth() const {
auto widthIter = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelXDimension"));
- if (widthIter != exifData_.end() && widthIter->count() > 0) {
- return widthIter->toUint32();
- }
- return 0;
+ if (widthIter == exifData_.end() || widthIter->count() == 0)
+ return 0;
+ return widthIter->toUint32();
}
uint32_t RafImage::pixelHeight() const {
auto heightIter = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelYDimension"));
- if (heightIter != exifData_.end() && heightIter->count() > 0) {
- return heightIter->toUint32();
- }
- return 0;
+ if (heightIter == exifData_.end() || heightIter->count() == 0)
+ return 0;
+ return heightIter->toUint32();
}
void RafImage::setExifData(const ExifData& /*exifData*/) {
@@ -72,7 +70,7 @@ void RafImage::printStructure(std::ostream& out, PrintStructureOption option, si
if (bPrint) {
io_->seek(0, BasicIo::beg); // rewind
size_t address = io_->tell();
- const char* format = " %8d | %8d | ";
+ const auto format = " %8d | %8d | ";
{
out << Internal::indent(depth) << "STRUCTURE OF RAF FILE: " << io().path() << std::endl;
diff --git a/src/riffvideo.cpp b/src/riffvideo.cpp
index e3a8b88f..be7235b7 100644
--- a/src/riffvideo.cpp
+++ b/src/riffvideo.cpp
@@ -389,7 +389,7 @@ void RiffVideo::readMetadata() {
decodeBlocks();
} // RiffVideo::readMetadata
-RiffVideo::HeaderReader::HeaderReader(BasicIo::UniquePtr& io) {
+RiffVideo::HeaderReader::HeaderReader(const BasicIo::UniquePtr& io) {
Internal::enforce(io->size() > io->tell() + DWORD + DWORD, Exiv2::ErrorCode::kerCorruptedMetadata);
id_ = readStringTag(io);
size_ = readDWORDTag(io);
@@ -402,7 +402,7 @@ bool RiffVideo::equal(const std::string& str1, const std::string& str2) {
return Internal::upper(str1) == str2;
}
-void RiffVideo::readList(HeaderReader& header_) {
+void RiffVideo::readList(const HeaderReader& header_) {
std::string chunk_type = readStringTag(io_);
#ifdef EXIV2_DEBUG_MESSAGES
@@ -417,7 +417,7 @@ void RiffVideo::readList(HeaderReader& header_) {
}
}
-void RiffVideo::readChunk(HeaderReader& header_) {
+void RiffVideo::readChunk(const HeaderReader& header_) {
#ifdef EXIV2_DEBUG_MESSAGES
if (header_.getSize())
EXV_INFO << "--> Reading Chunk : [" << header_.getId() << "] size= " << header_.getSize() << "(" << io_->tell()
@@ -457,8 +457,7 @@ void RiffVideo::readChunk(HeaderReader& header_) {
void RiffVideo::decodeBlocks() {
do {
- HeaderReader header(io_);
- if (equal(header.getId(), CHUNK_ID_LIST)) {
+ if (HeaderReader header(io_); equal(header.getId(), CHUNK_ID_LIST)) {
readList(header);
} else {
readChunk(header);
@@ -611,24 +610,20 @@ void RiffVideo::readStreamFormat(uint64_t size_) {
xmpData_["Xmp.video.ImageLength"] = readDWORDTag(io_);
xmpData_["Xmp.video.PixelPerMeterX"] = readQWORDTag(io_);
xmpData_["Xmp.video.PixelPerMeterY"] = readQWORDTag(io_);
- uint32_t NumOfColours = readDWORDTag(io_);
- if (NumOfColours == 0)
- xmpData_["Xmp.video.NumOfColours"] = "Unspecified";
- else
+ if (uint32_t NumOfColours = readDWORDTag(io_))
xmpData_["Xmp.video.NumOfColours"] = NumOfColours;
- uint32_t NumIfImpColours = readDWORDTag(io_);
- if (NumIfImpColours == 0)
- xmpData_["Xmp.video.NumIfImpColours"] = "All";
else
+ xmpData_["Xmp.video.NumOfColours"] = "Unspecified";
+ if (uint32_t NumIfImpColours = readDWORDTag(io_))
xmpData_["Xmp.video.NumIfImpColours"] = NumIfImpColours;
+ else
+ xmpData_["Xmp.video.NumIfImpColours"] = "All";
} else if (streamType_ == Audio) {
uint16_t format_tag = readWORDTag(io_);
- auto it = Internal::audioEncodingValues.find(format_tag);
- if (it != Internal::audioEncodingValues.end()) {
+ if (auto it = Internal::audioEncodingValues.find(format_tag); it != Internal::audioEncodingValues.end())
xmpData_["Xmp.audio.Compressor"] = it->second;
- } else {
+ else
xmpData_["Xmp.audio.Compressor"] = format_tag;
- }
xmpData_["Xmp.audio.ChannelType"] = getStreamType(readDWORDTag(io_));
xmpData_["Xmp.audio.SampleRate"] = readDWORDTag(io_); // nSamplesPerSec
@@ -657,10 +652,8 @@ void RiffVideo::readInfoListChunk(uint64_t size_) {
std::string type = readStringTag(io_);
size_t size = readDWORDTag(io_);
std::string content = readStringTag(io_, size);
- auto it = Internal::infoTags.find(type);
- if (it != Internal::infoTags.end()) {
+ if (auto it = Internal::infoTags.find(type); it != Internal::infoTags.end())
xmpData_[it->second] = content;
- }
current_size += DWORD * 2 + size;
}
}
diff --git a/src/rw2image.cpp b/src/rw2image.cpp
index f232112f..dc6e6be9 100644
--- a/src/rw2image.cpp
+++ b/src/rw2image.cpp
@@ -32,18 +32,16 @@ std::string Rw2Image::mimeType() const {
uint32_t Rw2Image::pixelWidth() const {
auto imageWidth = exifData_.findKey(Exiv2::ExifKey("Exif.PanasonicRaw.SensorWidth"));
- if (imageWidth != exifData_.end() && imageWidth->count() > 0) {
- return imageWidth->toUint32();
- }
- return 0;
+ if (imageWidth == exifData_.end() || imageWidth->count() == 0)
+ return 0;
+ return imageWidth->toUint32();
}
uint32_t Rw2Image::pixelHeight() const {
auto imageHeight = exifData_.findKey(Exiv2::ExifKey("Exif.PanasonicRaw.SensorHeight"));
- if (imageHeight != exifData_.end() && imageHeight->count() > 0) {
- return imageHeight->toUint32();
- }
- return 0;
+ if (imageHeight == exifData_.end() || imageHeight->count() == 0)
+ return 0;
+ return imageHeight->toUint32();
}
void Rw2Image::setExifData(const ExifData& /*exifData*/) {
diff --git a/src/samsungmn_int.cpp b/src/samsungmn_int.cpp
index 27178a88..138c9928 100644
--- a/src/samsungmn_int.cpp
+++ b/src/samsungmn_int.cpp
@@ -54,8 +54,7 @@ static std::ostream& printFocalLength35(std::ostream& os, const Value& value, co
if (value.count() != 1 || value.typeId() != unsignedLong) {
return os << value;
}
- const auto length = value.toInt64();
- if (length == 0) {
+ if (auto length = value.toInt64(); length == 0) {
os << _("Unknown");
} else {
std::ostringstream oss;
diff --git a/src/sigmamn_int.cpp b/src/sigmamn_int.cpp
index b537ee46..69d8ea85 100644
--- a/src/sigmamn_int.cpp
+++ b/src/sigmamn_int.cpp
@@ -73,8 +73,7 @@ const TagInfo* SigmaMakerNote::tagList() {
std::ostream& SigmaMakerNote::printStripLabel(std::ostream& os, const Value& value, const ExifData*) {
std::string v = value.toString();
- std::string::size_type pos = v.find(':');
- if (pos != std::string::npos) {
+ if (auto pos = v.find(':'); pos != std::string::npos) {
if (v.at(pos + 1) == ' ')
++pos;
v = v.substr(pos + 1);
diff --git a/src/sonymn_int.cpp b/src/sonymn_int.cpp
index 2851260f..17300985 100644
--- a/src/sonymn_int.cpp
+++ b/src/sonymn_int.cpp
@@ -1036,8 +1036,8 @@ std::ostream& SonyMakerNote::printWBShiftABGMPrecise(std::ostream& os, const Val
}
std::ios::fmtflags f(os.flags());
- const auto temp0 = static_cast(value.toInt64(0)) / (1000.0);
- const auto temp1 = static_cast(value.toInt64(1)) / (1000.0);
+ const auto temp0 = static_cast(value.toInt64(0)) / 1000.0;
+ const auto temp1 = static_cast(value.toInt64(1)) / 1000.0;
os << "A/B: ";
if (temp0 == 0) {
diff --git a/src/tags_int.cpp b/src/tags_int.cpp
index c0471683..20d3ff43 100644
--- a/src/tags_int.cpp
+++ b/src/tags_int.cpp
@@ -3013,12 +3013,10 @@ std::ostream& print0xa404(std::ostream& os, const Value& value, const ExifData*)
}
std::ostream& print0xa405(std::ostream& os, const Value& value, const ExifData*) {
- const auto length = value.toInt64();
- if (length == 0) {
+ if (auto length = value.toInt64(); length == 0)
os << _("Unknown");
- } else {
+ else
os << length << ".0 mm";
- }
return os;
}
diff --git a/src/tags_int.hpp b/src/tags_int.hpp
index 8285fc18..33ec7989 100644
--- a/src/tags_int.hpp
+++ b/src/tags_int.hpp
@@ -89,8 +89,7 @@ struct TagVocabulary {
*/
template
std::ostream& printTagString(std::ostream& os, const std::string& value, const ExifData*) {
- auto td = Exiv2::find(array, value);
- if (td) {
+ if (auto td = Exiv2::find(array, value)) {
os << exvGettext(td->label_);
} else {
os << "(" << value << ")";
@@ -146,8 +145,7 @@ std::ostream& printTagString4(std::ostream& os, const Value& value, const ExifDa
*/
template
std::ostream& printTagNoError(std::ostream& os, const int64_t value, const ExifData*) {
- auto td = Exiv2::find(array, value);
- if (td) {
+ if (auto td = Exiv2::find(array, value)) {
os << exvGettext(td->label_);
} else {
os << value;
@@ -173,8 +171,7 @@ std::ostream& printTagNoError(std::ostream& os, const Value& value, const ExifDa
*/
template
std::ostream& printTag(std::ostream& os, const int64_t value, const ExifData*) {
- auto td = Exiv2::find(array, value);
- if (td) {
+ if (auto td = Exiv2::find(array, value)) {
os << exvGettext(td->label_);
} else {
os << "(" << value << ")";
@@ -292,8 +289,7 @@ std::ostream& printTagBitlistAllLE(std::ostream& os, const Value& value, const E
*/
template
std::ostream& printTagVocabulary(std::ostream& os, const Value& value, const ExifData*) {
- auto td = Exiv2::find(array, value.toString());
- if (td) {
+ if (auto td = Exiv2::find(array, value.toString())) {
os << exvGettext(td->label_);
} else {
os << "(" << value << ")";
diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp
index a62092eb..d182bcd6 100644
--- a/src/tiffcomposite_int.cpp
+++ b/src/tiffcomposite_int.cpp
@@ -92,9 +92,6 @@ TiffBinaryArray::TiffBinaryArray(uint16_t tag, IfdId group, const ArraySet* arra
// We'll figure out the correct cfg later
}
-TiffBinaryElement::TiffBinaryElement(uint16_t tag, IfdId group) : TiffEntryBase(tag, group) {
-}
-
TiffDirectory::~TiffDirectory() {
for (auto&& component : components_) {
delete component;
@@ -207,8 +204,7 @@ void TiffEntryBase::setData(byte* pData, size_t size, std::shared_ptr s
void TiffEntryBase::updateValue(Value::UniquePtr value, ByteOrder byteOrder) {
if (!value)
return;
- size_t newSize = value->size();
- if (newSize > size_) {
+ if (size_t newSize = value->size(); newSize > size_) {
auto d = std::make_shared(newSize);
setData(std::move(d));
}
@@ -488,19 +484,19 @@ TiffComponent* TiffSubIfd::doAddPath(uint16_t tag, TiffPath& tiffPath, TiffCompo
const TiffPathItem tpi2 = tiffPath.top();
tiffPath.push(tpi1);
auto it = std::find_if(ifds_.begin(), ifds_.end(), [&](auto&& ifd) { return ifd->group() == tpi2.group(); });
- if (it != ifds_.end())
- return (*it)->addPath(tag, tiffPath, pRoot, std::move(object));
-
- auto tc = [&] {
- if (tiffPath.size() == 1 && object) {
- TiffComponent::UniquePtr tempObject;
- std::swap(object, tempObject);
- return addChild(std::move(tempObject));
- }
- return addChild(std::make_unique(tpi1.tag(), tpi2.group()));
- }();
- setCount(ifds_.size());
- return tc->addPath(tag, tiffPath, pRoot, std::move(object));
+ if (it == ifds_.end()) {
+ auto tc = [&] {
+ if (tiffPath.size() == 1 && object) {
+ TiffComponent::UniquePtr tempObject;
+ std::swap(object, tempObject);
+ return addChild(std::move(tempObject));
+ }
+ return addChild(std::make_unique(tpi1.tag(), tpi2.group()));
+ }();
+ setCount(ifds_.size());
+ return tc->addPath(tag, tiffPath, pRoot, std::move(object));
+ }
+ return (*it)->addPath(tag, tiffPath, pRoot, std::move(object));
} // TiffSubIfd::doAddPath
TiffComponent* TiffMnEntry::doAddPath(uint16_t tag, TiffPath& tiffPath, TiffComponent* pRoot,
@@ -844,8 +840,7 @@ size_t TiffDirectory::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, size_t
size_t sizeValue = 0;
size_t sizeData = 0;
for (auto&& component : components_) {
- size_t sv = component->size();
- if (sv > 4) {
+ if (size_t sv = component->size(); sv > 4) {
sv += sv & 1; // Align value to word boundary
sizeValue += sv;
}
@@ -873,8 +868,7 @@ size_t TiffDirectory::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, size_t
// b) Directory entries - may contain pointers to the value or data
for (auto&& component : components_) {
idx += writeDirEntry(ioWrapper, byteOrder, offset, component, valueIdx, dataIdx, imageIdx);
- size_t sv = component->size();
- if (sv > 4) {
+ if (size_t sv = component->size(); sv > 4) {
sv += sv & 1; // Align value to word boundary
valueIdx += sv;
}
@@ -896,8 +890,7 @@ size_t TiffDirectory::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, size_t
valueIdx = sizeDir;
dataIdx = sizeDir + sizeValue;
for (auto&& component : components_) {
- size_t sv = component->size();
- if (sv > 4) {
+ if (size_t sv = component->size(); sv > 4) {
size_t d = component->write(ioWrapper, byteOrder, offset, valueIdx, dataIdx, imageIdx);
enforce(sv == d, ErrorCode::kerImageWriteFailed);
if ((sv & 1) == 1) {
@@ -1291,8 +1284,7 @@ size_t TiffDirectory::doSize() const {
size_t len = 2 + 12 * compCount + (hasNext_ ? 4 : 0);
// Size of IFD values and data
for (auto&& component : components_) {
- size_t sv = component->size();
- if (sv > 4) {
+ if (size_t sv = component->size(); sv > 4) {
sv += sv & 1; // Align value to word boundary
len += sv;
}
@@ -1459,11 +1451,12 @@ static const TagInfo* findTagInfo(uint16_t tag, IfdId group) {
return Internal::gpsTagList();
return group == IfdId::exifId ? Internal::exifTagList() : nullptr;
}();
- if (tags) {
- for (size_t idx = 0; !result && tags[idx].tag_ != 0xffff; ++idx) {
- if (tags[idx].tag_ == tag) {
- result = tags + idx;
- }
+ if (!tags)
+ return result;
+
+ for (size_t idx = 0; !result && tags[idx].tag_ != 0xffff; ++idx) {
+ if (tags[idx].tag_ == tag) {
+ result = tags + idx;
}
}
return result;
diff --git a/src/tiffcomposite_int.hpp b/src/tiffcomposite_int.hpp
index ecfc00f9..5fbc10fa 100644
--- a/src/tiffcomposite_int.hpp
+++ b/src/tiffcomposite_int.hpp
@@ -1409,13 +1409,9 @@ class TiffBinaryArray : public TiffEntryBase {
@brief Element of a TiffBinaryArray.
*/
class TiffBinaryElement : public TiffEntryBase {
- public:
- //! @name Creators
- //@{
- //! Constructor
- TiffBinaryElement(uint16_t tag, IfdId group);
- //@}
+ using TiffEntryBase::TiffEntryBase;
+ public:
//! @name Manipulators
//@{
/*!
diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp
index e530d983..22086760 100644
--- a/src/tiffimage_int.cpp
+++ b/src/tiffimage_int.cpp
@@ -12,9 +12,9 @@
#include
// Shortcuts for the newTiffBinaryArray templates.
-#define EXV_BINARY_ARRAY(arrayCfg, arrayDef) (newTiffBinaryArray0)
-#define EXV_SIMPLE_BINARY_ARRAY(arrayCfg) (newTiffBinaryArray1)
-#define EXV_COMPLEX_BINARY_ARRAY(arraySet, cfgSelFct) (newTiffBinaryArray2)
+#define EXV_BINARY_ARRAY(arrayCfg, arrayDef) &newTiffBinaryArray0
+#define EXV_SIMPLE_BINARY_ARRAY(arrayCfg) &newTiffBinaryArray1
+#define EXV_COMPLEX_BINARY_ARRAY(arraySet, cfgSelFct) &newTiffBinaryArray2
namespace Exiv2::Internal {
//! Constant for non-encrypted binary arrays
diff --git a/src/types.cpp b/src/types.cpp
index aa15cd87..95857762 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -490,7 +490,12 @@ bool isHex(const std::string& str, size_t size, const std::string& prefix) {
int exifTime(const char* buf, tm* tm) {
int rc = 1;
- int year = 0, mon = 0, mday = 0, hour = 0, min = 0, sec = 0;
+ int year = 0;
+ int mon = 0;
+ int mday = 0;
+ int hour = 0;
+ int min = 0;
+ int sec = 0;
if (std::sscanf(buf, "%4d:%2d:%2d %2d:%2d:%2d", &year, &mon, &mday, &hour, &min, &sec) == 6) {
tm->tm_year = year - 1900;
tm->tm_mon = mon - 1;
diff --git a/src/tzfile.h b/src/tzfile.h
index d031166e..f629067a 100644
--- a/src/tzfile.h
+++ b/src/tzfile.h
@@ -25,7 +25,7 @@
#ifndef lint
#ifndef NOID
-static char tzfilehid[] = "@(#)tzfile.h 7.14";
+static char tzfilehid[] = "@(#)tzfile.h\t7.14";
#endif /* !defined NOID */
#endif /* !defined lint */
diff --git a/src/webpimage.cpp b/src/webpimage.cpp
index bf296888..3fb617ac 100644
--- a/src/webpimage.cpp
+++ b/src/webpimage.cpp
@@ -503,9 +503,7 @@ void WebPImage::decodeChunks(uint32_t filesize) {
Internal::enforce(io_->tell() <= filesize, Exiv2::ErrorCode::kerCorruptedMetadata);
Internal::enforce(size <= (filesize - io_->tell()), Exiv2::ErrorCode::kerCorruptedMetadata);
- DataBuf payload(size);
-
- if (payload.empty()) {
+ if (DataBuf payload(size); payload.empty()) {
io_->seek(size, BasicIo::cur);
} else if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8X) && !has_canvas_data) {
Internal::enforce(size >= 10, Exiv2::ErrorCode::kerCorruptedMetadata);
@@ -594,22 +592,22 @@ void WebPImage::decodeChunks(uint32_t filesize) {
bool s_header = false;
bool le_header = false;
bool be_header = false;
- size_t pos = getHeaderOffset(payload.c_data(), payload.size(), reinterpret_cast(&exifLongHeader), 4);
+ size_t pos = getHeaderOffset(payload.c_data(), payload.size(), exifLongHeader, 4);
if (pos == std::string::npos) {
- pos = getHeaderOffset(payload.c_data(), payload.size(), reinterpret_cast(&exifLongHeader), 6);
+ pos = getHeaderOffset(payload.c_data(), payload.size(), exifLongHeader, 6);
if (pos != std::string::npos) {
s_header = true;
}
}
if (pos == std::string::npos) {
- pos = getHeaderOffset(payload.c_data(), payload.size(), reinterpret_cast(&exifTiffLEHeader), 3);
+ pos = getHeaderOffset(payload.c_data(), payload.size(), exifTiffLEHeader, 3);
if (pos != std::string::npos) {
le_header = true;
}
}
if (pos == std::string::npos) {
- pos = getHeaderOffset(payload.c_data(), payload.size(), reinterpret_cast(&exifTiffBEHeader), 4);
+ pos = getHeaderOffset(payload.c_data(), payload.size(), exifTiffBEHeader, 4);
if (pos != std::string::npos) {
be_header = true;
}
diff --git a/src/xmp.cpp b/src/xmp.cpp
index 6b68ea78..68abc9d9 100644
--- a/src/xmp.cpp
+++ b/src/xmp.cpp
@@ -462,7 +462,7 @@ XmpData::const_iterator XmpData::end() const {
}
bool XmpData::empty() const {
- return count() == 0;
+ return xmpMetadata_.empty();
}
long XmpData::count() const {
@@ -685,7 +685,9 @@ int XmpParser::decode(XmpData& xmpData, const std::string& xmpPacket) {
XMLValidator::check(xmpPacket.data(), len);
SXMPMeta meta(xmpPacket.data(), static_cast(len));
SXMPIterator iter(meta);
- std::string schemaNs, propPath, propValue;
+ std::string schemaNs;
+ std::string propPath;
+ std::string propValue;
XMP_OptionBits opt = 0;
while (iter.Next(&schemaNs, &propPath, &propValue, &opt)) {
printNode(schemaNs, propPath, propValue, opt);
@@ -734,7 +736,9 @@ int XmpParser::decode(XmpData& xmpData, const std::string& xmpPacket) {
// Check if all elements are simple
bool simpleArray = true;
SXMPIterator aIter(meta, schemaNs.c_str(), propPath.c_str());
- std::string aSchemaNs, aPropPath, aPropValue;
+ std::string aSchemaNs;
+ std::string aPropPath;
+ std::string aPropValue;
XMP_OptionBits aOpt = 0;
while (aIter.Next(&aSchemaNs, &aPropPath, &aPropValue, &aOpt)) {
if (propPath == aPropPath)
diff --git a/unitTests/test_basicio.cpp b/unitTests/test_basicio.cpp
index 8ccecfc4..68236e6d 100644
--- a/unitTests/test_basicio.cpp
+++ b/unitTests/test_basicio.cpp
@@ -144,27 +144,27 @@ TEST(MemIo, readEmptyIoReturns0) {
}
TEST(MemIo, readLessBytesThanAvailableReturnsRequestedBytes) {
- std::array buf1, buf2;
+ std::array buf1;
+ std::array buf2 = {};
buf1.fill(1);
- buf2.fill(0);
MemIo io(buf1.data(), buf1.size());
ASSERT_EQ(5, io.read(buf2.data(), 5));
}
TEST(MemIo, readSameBytesThanAvailableReturnsRequestedBytes) {
- std::array buf1, buf2;
+ std::array buf1;
+ std::array buf2 = {};
buf1.fill(1);
- buf2.fill(0);
MemIo io(buf1.data(), buf1.size());
ASSERT_EQ(10, io.read(buf2.data(), 10));
}
TEST(MemIo, readMoreBytesThanAvailableReturnsAvailableBytes) {
- std::array buf1, buf2;
+ std::array buf1;
+ std::array buf2 = {};
buf1.fill(1);
- buf2.fill(0);
MemIo io(buf1.data(), buf1.size());
ASSERT_EQ(10, io.read(buf2.data(), 15));