Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/app_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "app_utils.hpp"
#include <climits>
#include <cstdint>
#include <cstdlib>
#include <limits>

Expand Down
1 change: 0 additions & 1 deletion app/exiv2app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <exiv2/exiv2.hpp>

#include "getopt.hpp"
#include "types.hpp"

// + standard includes
#include <iostream>
Expand Down
6 changes: 3 additions & 3 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char[]>(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();
Expand Down
2 changes: 1 addition & 1 deletion src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down
4 changes: 3 additions & 1 deletion src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -281,7 +283,7 @@ void CiffHeader::write(Blob& blob) const {
ul2Data(buf, offset_, byteOrder_);
append(blob, buf, 4);
o += 4;
append(blob, reinterpret_cast<const byte*>(signature_), 8);
append(blob, signature_, 8);
o += 8;
// Pad as needed
if (!pPadding_.empty()) {
Expand Down
4 changes: 2 additions & 2 deletions src/crwimage_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class CiffHeader {
//@}

//! Return a pointer to the Canon CRW signature.
static const char* signature() {
static auto signature() {
return signature_;
}

Expand Down Expand Up @@ -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<CiffDirectory> pRootDir_; //!< Pointer to the root directory
ByteOrder byteOrder_ = littleEndian; //!< Applicable byte order
Expand Down
2 changes: 2 additions & 0 deletions src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// + standard includes
#include <array>
#include <iostream>
#include <string>
#include <utility>

namespace {
//! Complete list of Exiv2 exception error messages
Expand Down
3 changes: 3 additions & 0 deletions src/pgfimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
#include "error.hpp"
#include "futils.hpp"
#include "image.hpp"
#include "types.hpp"

#include <array>
#include <cstdint>
#include <cstring>
#include <limits>
#include <utility>

#ifdef EXIV2_DEBUG_MESSAGES
#include <iostream>
Expand Down
8 changes: 2 additions & 6 deletions src/quicktimevideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/sonymn_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Exiv2 {
class ExifData;
class Value;
struct DataBuf;
struct TagInfo;
namespace Internal {
// *****************************************************************************
Expand Down Expand Up @@ -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
Expand Down
24 changes: 11 additions & 13 deletions src/tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(unknownTag.sectionId_)].name_;
return sectionInfo[static_cast<int>(ti->sectionId_)].name_;
if (auto ti = tagInfo(key.tag(), key.ifdId()))
return sectionInfo[static_cast<int>(ti->sectionId_)].name_;
return sectionInfo[static_cast<int>(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) {
Expand Down Expand Up @@ -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<Impl>()) {
Expand Down
7 changes: 4 additions & 3 deletions src/tags_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"))
Expand Down
1 change: 0 additions & 1 deletion src/tags_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

// *****************************************************************************
// included header files
#include "types.hpp"
#include "value.hpp"

#include "i18n.h"
Expand Down
19 changes: 11 additions & 8 deletions src/tiffcomposite_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
#include "value.hpp"

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <memory>
#include <numeric>
#include <string>
#include <utility>

// *****************************************************************************
namespace {
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/tiffcomposite_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// *****************************************************************************
// included header files
#include "tifffwd_int.hpp"
#include "types.hpp"

#include <memory>

Expand Down
1 change: 0 additions & 1 deletion src/tifffwd_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

// *****************************************************************************
// included header files
#include "types.hpp"

// + standard includes
#include <memory>
Expand Down
2 changes: 2 additions & 0 deletions src/tiffimage_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// *****************************************************************************
// included header files
#include "tifffwd_int.hpp"
#include "types.hpp"

#include <map>
#include <unordered_map>
Expand All @@ -17,6 +18,7 @@ class BasicIo;
class ExifData;
class IptcData;
class XmpData;
struct DataBuf;

namespace Internal {
/*!
Expand Down
4 changes: 2 additions & 2 deletions src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void TiffDecoder::decodeCanonAFInfo(const TiffEntryBase* object) {
std::vector<uint16_t> 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<int16_t>(object->pValue()->count()) * 2)
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ std::ostream& operator<<(std::ostream& os, const Rational& r) {
return os << r.first << "/" << r.second;
}

template <typename T>
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;
Expand Down
3 changes: 1 addition & 2 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

namespace Exiv2::Internal {

template <typename T>
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
Expand Down
4 changes: 3 additions & 1 deletion src/webpimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
#include <cstring>
#include <iostream>

#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;
Expand Down Expand Up @@ -67,6 +68,7 @@ namespace {
return hexOutput.str();
}
} // namespace
#endif

// *****************************************************************************
// class member definitions
Expand Down
6 changes: 3 additions & 3 deletions src/xmpsidecar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>(buf), l);
auto buf = std::make_unique<byte[]>(len);
while (auto l = io_->read(buf.get(), len)) {
xmpPacket.append(reinterpret_cast<char*>(buf.get()), l);
}
if (io_->error())
throw Error(ErrorCode::kerFailedToReadImageData);
Expand Down