Skip to content

Commit

Permalink
Fix issues on ARM builds (#2205)
Browse files Browse the repository at this point in the history
* Specify base class initialization in Copy Constructor

* Fix printing of uint64_t variable in ARM 32bits

Use cinttypes

* Fix alignment issues on ARM 32 bits

* tests: add assertion with custom message
  • Loading branch information
piponazo authored Apr 13, 2022
1 parent 6203ded commit 941017d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/bmffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "types.hpp"

// + standard includes
#include <cinttypes>
#include <cstdio>
#include <cstring>
#include <iostream>
Expand Down Expand Up @@ -184,7 +185,7 @@ long BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintStruc
if (bTrace) {
bLF = true;
out << indent(depth) << "Exiv2::BmffImage::boxHandler: " << toAscii(box_type)
<< Internal::stringFormat(" %8ld->%lu ", address, box_length);
<< Internal::stringFormat(" %8ld->%" PRIu64 " ", address, box_length);
}

if (box_length == 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/datasets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ IptcKey::IptcKey(uint16_t tag, uint16_t record) : tag_(tag), record_(record) {
makeKey();
}

IptcKey::IptcKey(const IptcKey& rhs) : tag_(rhs.tag_), record_(rhs.record_), key_(rhs.key_) {
IptcKey::IptcKey(const IptcKey& rhs) : Key(), tag_(rhs.tag_), record_(rhs.record_), key_(rhs.key_) {
}

std::string IptcKey::key() const {
Expand Down
18 changes: 6 additions & 12 deletions src/jp2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,25 +604,20 @@ void Jp2Image::encodeJp2Header(const DataBuf& boxBuf, DataBuf& outBuf) {
size_t outlen = boxHSize; // now many bytes have we written to output?
size_t inlen = boxHSize; // how many bytes have we read from boxBuf?
enforce(boxHSize <= output.size(), ErrorCode::kerCorruptedMetadata);
auto pBox = reinterpret_cast<const Internal::Jp2BoxHeader*>(boxBuf.c_data());
uint32_t length = getLong(reinterpret_cast<const byte*>(&pBox->length), bigEndian);
uint32_t length = getLong(boxBuf.c_data(0), bigEndian);
enforce(length <= output.size(), ErrorCode::kerCorruptedMetadata);
uint32_t count = boxHSize;
auto p = boxBuf.c_str();
bool bWroteColor = false;

while (count < length && !bWroteColor) {
enforce(boxHSize <= length - count, ErrorCode::kerCorruptedMetadata);
auto pSubBox = reinterpret_cast<const Internal::Jp2BoxHeader*>(p + count);

// copy data. pointer could be into a memory mapped file which we will decode!
Internal::Jp2BoxHeader subBox;
memcpy(&subBox, pSubBox, boxHSize);
memcpy(&subBox, boxBuf.c_data(count), boxHSize);
Internal::Jp2BoxHeader newBox = subBox;

if (count < length) {
subBox.length = getLong(reinterpret_cast<byte*>(&subBox.length), bigEndian);
subBox.type = getLong(reinterpret_cast<byte*>(&subBox.type), bigEndian);
subBox.length = getLong(boxBuf.c_data(count), bigEndian);
subBox.type = getLong(boxBuf.c_data(count + 4), bigEndian);
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Jp2Image::encodeJp2Header subbox: " << toAscii(subBox.type) << " length = " << subBox.length
<< std::endl;
Expand Down Expand Up @@ -671,9 +666,8 @@ void Jp2Image::encodeJp2Header(const DataBuf& boxBuf, DataBuf& outBuf) {
// allocate the correct number of bytes, copy the data and update the box header
outBuf.alloc(outlen);
std::copy_n(output.c_data(), outlen, outBuf.begin());
auto oBox = reinterpret_cast<Internal::Jp2BoxHeader*>(outBuf.data());
ul2Data(reinterpret_cast<byte*>(&oBox->type), kJp2BoxTypeHeader, bigEndian);
ul2Data(reinterpret_cast<byte*>(&oBox->length), static_cast<uint32_t>(outlen), bigEndian);
ul2Data(outBuf.data(0), static_cast<uint32_t>(outlen), bigEndian);
ul2Data(outBuf.data(4), kJp2BoxTypeHeader, bigEndian);
}

#ifdef __clang__
Expand Down
2 changes: 1 addition & 1 deletion src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5097,7 +5097,7 @@ XmpKey::XmpKey(const std::string& prefix, const std::string& property) : p_(std:

XmpKey::~XmpKey() = default;

XmpKey::XmpKey(const XmpKey& rhs) : p_(std::make_unique<Impl>(*rhs.p_)) {
XmpKey::XmpKey(const XmpKey& rhs) : Key(), p_(std::make_unique<Impl>(*rhs.p_)) {
}

XmpKey& XmpKey::operator=(const XmpKey& rhs) {
Expand Down
2 changes: 1 addition & 1 deletion src/tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ ExifKey::ExifKey(const std::string& key) : p_(std::make_unique<Impl>()) {
p_->decomposeKey(key);
}

ExifKey::ExifKey(const ExifKey& rhs) : p_(std::make_unique<Impl>(*rhs.p_)) {
ExifKey::ExifKey(const ExifKey& rhs) : Key(), p_(std::make_unique<Impl>(*rhs.p_)) {
}

ExifKey::~ExifKey() = default;
Expand Down
1 change: 1 addition & 0 deletions tests/bash_tests/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ def test1120(img):
BT.copyTestFile('large.icc', iccname)
out += BT.Executer('exiv2 -iC {img}', vars())
e = BT.Executer('exiv2 -pC {img}', vars(), compatible_output=False, decode_output=False)
self.assertIsNotNone(e.stdout, msg="Empty ICC profile in {}".format(img))
BT.save(e.stdout, stub + '_large_1.icc')
out += BT.Executer('exiv2 -pS {img}', vars())
out += BT.Executer('exiv2 -eC --force {img}', vars())
Expand Down

0 comments on commit 941017d

Please sign in to comment.