Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy 19 fixes. #3076

Merged
merged 3 commits into from
Nov 26, 2024
Merged
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
4 changes: 2 additions & 2 deletions app/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static int setModeAndPrintStructure(Exiv2::PrintStructureOption option, const st
std::string str = output.str();
if (result == 0 && !str.empty()) {
Exiv2::DataBuf iccProfile(str.size());
Exiv2::DataBuf ascii(str.size() * 3 + 1);
Exiv2::DataBuf ascii((str.size() * 3) + 1);
ascii.write_uint8(str.size() * 3, 0);
std::copy(str.begin(), str.end(), iccProfile.begin());
if (Exiv2::base64encode(iccProfile.c_data(), str.size(), reinterpret_cast<char*>(ascii.data()), str.size() * 3)) {
Expand Down Expand Up @@ -1827,7 +1827,7 @@ int renameFile(std::string& newPath, const tm* tm) {
auto oldFsPath = fs::path(path);
std::string format = Params::instance().format_;
std::string filename = p.stem().string();
std::string basesuffix = "";
std::string basesuffix;
int pos = filename.find('.');
if (pos > 0)
basesuffix = filename.substr(filename.find('.'));
Expand Down
3 changes: 2 additions & 1 deletion app/actions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
#define ACTIONS_HPP_

// *****************************************************************************
#include <unordered_map>
#include "exiv2app.hpp"

#include <unordered_map>

// *****************************************************************************
// class declarations

Expand Down
3 changes: 2 additions & 1 deletion include/exiv2/asfvideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#pragma once

// *****************************************************************************
#include <array>
#include "exiv2lib_export.h"

// included header files
#include "image.hpp"

#include <array>

// *****************************************************************************
// namespace extensions
namespace Exiv2 {
Expand Down
16 changes: 7 additions & 9 deletions include/exiv2/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,13 +792,11 @@ class EXIV2API XmpArrayValue : public XmpValue {
struct LangAltValueComparator {
//! LangAltValueComparator comparison case insensitive function
bool operator()(const std::string& str1, const std::string& str2) const {
int result = str1.size() < str2.size() ? 1 : str1.size() > str2.size() ? -1 : 0;
if (result == 0) {
for (auto c1 = str1.begin(), c2 = str2.begin(); result == 0 && c1 != str1.end(); ++c1, ++c2) {
result = tolower(*c1) < tolower(*c2) ? 1 : tolower(*c1) > tolower(*c2) ? -1 : 0;
}
}
return result < 0;
if (str1.size() != str2.size())
return str1.size() > str2.size();

auto f = [](unsigned char a, unsigned char b) { return std::tolower(a) > std::tolower(b); };
return std::lexicographical_compare(str1.begin(), str1.end(), str2.begin(), str2.end(), f);
}
};

Expand Down Expand Up @@ -1216,7 +1214,7 @@ class ValueType : public Value {
private:
//! Utility for toInt64, toUint32, etc.
template <typename I>
inline I float_to_integer_helper(size_t n) const {
I float_to_integer_helper(size_t n) const {
const auto v = value_.at(n);
if (static_cast<decltype(v)>(std::numeric_limits<I>::min()) <= v &&
v <= static_cast<decltype(v)>(std::numeric_limits<I>::max())) {
Expand All @@ -1227,7 +1225,7 @@ class ValueType : public Value {

//! Utility for toInt64, toUint32, etc.
template <typename I>
inline I rational_to_integer_helper(size_t n) const {
I rational_to_integer_helper(size_t n) const {
auto a = value_.at(n).first;
auto b = value_.at(n).second;

Expand Down
2 changes: 1 addition & 1 deletion samples/geotag.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Sample program to read gpx files and update images with GPS tags

#include <expat.h>
#include <exiv2/exiv2.hpp>

#include <expat.h>
#include <sys/stat.h>
#include <sys/types.h>

Expand Down
2 changes: 1 addition & 1 deletion samples/iptctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int main(int argc, char* const argv[]) {
std::string line;
int num = 0;
std::getline(std::cin, line);
while (line.length() && processLine(line, ++num, image->iptcData())) {
while (!line.empty() && processLine(line, ++num, image->iptcData())) {
std::getline(std::cin, line);
}

Expand Down
6 changes: 3 additions & 3 deletions src/asfvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) {
std::memcpy(&data1_, bytes, DWORD);
std::memcpy(&data2_, bytes + DWORD, WORD);
std::memcpy(&data3_, bytes + DWORD + WORD, WORD);
std::copy(bytes + QWORD, bytes + 2 * QWORD, data4_.begin());
std::copy(bytes + QWORD, bytes + (2 * QWORD), data4_.begin());
if (isBigEndianPlatform()) {
data1_ = byteSwap(data1_, true);
data2_ = byteSwap(data2_, true);
Expand Down Expand Up @@ -295,7 +295,7 @@ void AsfVideo::decodeHeader() {

uint32_t nb_headers = Exiv2::getULong(nbHeadersBuf.data(), littleEndian);
Internal::enforce(nb_headers < std::numeric_limits<uint32_t>::max(), Exiv2::ErrorCode::kerCorruptedMetadata);
io_->seekOrThrow(io_->tell() + BYTE * 2, BasicIo::beg,
io_->seekOrThrow(io_->tell() + (BYTE * 2), BasicIo::beg,
ErrorCode::kerFailedToReadImageData); // skip two reserved tags
for (uint32_t i = 0; i < nb_headers; i++) {
decodeBlock();
Expand Down Expand Up @@ -346,7 +346,7 @@ void AsfVideo::DegradableJPEGMedia() {
height_ = height;
xmpData_["Xmp.video.Height"] = height;

io_->seek(io_->tell() + WORD * 3 /*3 Reserved*/, BasicIo::beg);
io_->seek(io_->tell() + (WORD * 3) /*3 Reserved*/, BasicIo::beg);

uint32_t interchange_data_length = readWORDTag(io_);
io_->seek(io_->tell() + interchange_data_length /*Interchange data*/, BasicIo::beg);
Expand Down
19 changes: 9 additions & 10 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "image_int.hpp"
#include "types.hpp"

#include <algorithm>
#include <cstdio> // for remove, rename
#include <cstdlib> // for alloc, realloc, free
#include <cstring> // std::memcpy
Expand Down Expand Up @@ -655,8 +656,7 @@ void MemIo::Impl::reserve(size_t wcount) {
if (need > size_) {
if (need > sizeAlloced_) {
blockSize = 2 * sizeAlloced_;
if (blockSize > maxBlockSize)
blockSize = maxBlockSize;
blockSize = std::min(blockSize, maxBlockSize);
// Allocate in blocks
size_t want = blockSize * (1 + need / blockSize);
data_ = static_cast<byte*>(std::realloc(data_, want));
Expand Down Expand Up @@ -1241,7 +1241,7 @@ size_t RemoteIo::read(byte* buf, size_t rcount) {
}

size_t iBlock = lowBlock;
size_t startPos = p_->idx_ - lowBlock * p_->blockSize_;
size_t startPos = p_->idx_ - (lowBlock * p_->blockSize_);
size_t totalRead = 0;
do {
auto data = p_->blocksMap_[iBlock++].getData();
Expand Down Expand Up @@ -1273,7 +1273,7 @@ int RemoteIo::getb() {
p_->populateBlocks(expectedBlock, expectedBlock);

auto data = p_->blocksMap_[expectedBlock].getData();
return data[p_->idx_++ - expectedBlock * p_->blockSize_];
return data[p_->idx_++ - (expectedBlock * p_->blockSize_)];
}

void RemoteIo::transfer(BasicIo& src) {
Expand Down Expand Up @@ -1303,8 +1303,7 @@ int RemoteIo::seek(int64_t offset, Position pos) {
// if (newIdx < 0 || newIdx > (long) p_->size_) return 1;
p_->idx_ = static_cast<size_t>(newIdx);
p_->eof_ = newIdx > static_cast<int64_t>(p_->size_);
if (p_->idx_ > p_->size_)
p_->idx_ = p_->size_;
p_->idx_ = std::min(p_->idx_, p_->size_);
return 0;
}

Expand Down Expand Up @@ -1439,7 +1438,7 @@ void HttpIo::HttpImpl::getDataByRange(size_t lowBlock, size_t highBlock, std::st
std::string errors;
if (lowBlock != std::numeric_limits<size_t>::max() && highBlock != std::numeric_limits<size_t>::max()) {
std::stringstream ss;
ss << "Range: bytes=" << lowBlock * blockSize_ << "-" << ((highBlock + 1) * blockSize_ - 1) << "\r\n";
ss << "Range: bytes=" << lowBlock * blockSize_ << "-" << (((highBlock + 1) * blockSize_) - 1) << "\r\n";
request["header"] = ss.str();
}

Expand Down Expand Up @@ -1475,7 +1474,7 @@ void HttpIo::HttpImpl::writeRemote(const byte* data, size_t size, size_t from, s
request["verb"] = "POST";

// encode base64
size_t encodeLength = ((size + 2) / 3) * 4 + 1;
size_t encodeLength = (((size + 2) / 3) * 4) + 1;
std::vector<char> encodeData(encodeLength);
base64encode(data, size, encodeData.data(), encodeLength);
// url encode
Expand Down Expand Up @@ -1618,7 +1617,7 @@ void CurlIo::CurlImpl::getDataByRange(size_t lowBlock, size_t highBlock, std::st

if (lowBlock != std::numeric_limits<size_t>::max() && highBlock != std::numeric_limits<size_t>::max()) {
std::stringstream ss;
ss << lowBlock * blockSize_ << "-" << ((highBlock + 1) * blockSize_ - 1);
ss << lowBlock * blockSize_ << "-" << (((highBlock + 1) * blockSize_) - 1);
std::string range = ss.str();
curl_easy_setopt(curl_, CURLOPT_RANGE, range.c_str());
}
Expand Down Expand Up @@ -1658,7 +1657,7 @@ void CurlIo::CurlImpl::writeRemote(const byte* data, size_t size, size_t from, s
curl_easy_setopt(curl_, CURLOPT_SSL_VERIFYPEER, 0L);

// encode base64
size_t encodeLength = ((size + 2) / 3) * 4 + 1;
size_t encodeLength = (((size + 2) / 3) * 4) + 1;
std::vector<char> encodeData(encodeLength);
base64encode(data, size, encodeData.data(), encodeLength);
// url encode
Expand Down
5 changes: 2 additions & 3 deletions src/canonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2836,9 +2836,8 @@ std::ostream& CanonMakerNote::print0x000c(std::ostream& os, const Value& value,
is >> l;
return os << std::setw(4) << std::setfill('0') << std::hex << ((l & 0xffff0000) >> 16) << std::setw(5)
<< std::setfill('0') << std::dec << (l & 0x0000ffff);
} else {
return os << value;
}
return os << value;
}

std::ostream& CanonMakerNote::printCs0x0002(std::ostream& os, const Value& value, const ExifData*) {
Expand Down Expand Up @@ -3172,7 +3171,7 @@ std::ostream& CanonMakerNote::printSi0x0017(std::ostream& os, const Value& value

std::ostringstream oss;
oss.copyfmt(os);
os << std::fixed << std::setprecision(2) << value.toInt64() / 8.0 - 6.0;
os << std::fixed << std::setprecision(2) << (value.toInt64() / 8.0) - 6.0;
os.copyfmt(oss);
return os;
}
Expand Down
4 changes: 2 additions & 2 deletions src/casiomn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ std::ostream& CasioMakerNote::print0x0015(std::ostream& os, const Value& value,

if (numbers.size() >= 10) {
// year
long l = (numbers[0] - 48) * 10 + (numbers[1] - 48);
long l = ((numbers[0] - 48) * 10) + (numbers[1] - 48);
if (l < 70)
l += 2000;
else
Expand Down Expand Up @@ -470,7 +470,7 @@ std::ostream& Casio2MakerNote::print0x2001(std::ostream& os, const Value& value,

if (numbers.size() >= 10) {
// year
long l = (numbers[0] - 48) * 10 + (numbers[1] - 48);
long l = ((numbers[0] - 48) * 10) + (numbers[1] - 48);
if (l < 70)
l += 2000;
else
Expand Down
3 changes: 1 addition & 2 deletions src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#ifdef EXV_HAVE_ICONV
#include <iconv.h>
#include <cerrno>
#elif defined _WIN32
#include <windows.h>
#endif
Expand Down Expand Up @@ -829,7 +828,7 @@ void Converter::cnvExifGPSCoord(const char* from, const char* to) {
// Hack: Need Value::toDouble
deg[i] = static_cast<double>(z) / d;
}
double min = deg[0] * 60.0 + deg[1] + deg[2] / 60.0;
double min = (deg[0] * 60.0) + deg[1] + (deg[2] / 60.0);
auto ideg = static_cast<int>(min / 60.0);
min -= ideg * 60;
std::ostringstream oss;
Expand Down
21 changes: 12 additions & 9 deletions src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "error.hpp"
#include "i18n.h" // NLS support.

#include <algorithm>
#include <ctime>
#include <iostream>

Expand Down Expand Up @@ -580,7 +581,7 @@ void CiffHeader::remove(uint16_t crwTagId, uint16_t crwDir) const {
} // CiffHeader::remove

void CiffComponent::remove(CrwDirs& crwDirs, uint16_t crwTagId) {
return doRemove(crwDirs, crwTagId);
doRemove(crwDirs, crwTagId);
} // CiffComponent::remove

void CiffComponent::doRemove(CrwDirs& /*crwDirs*/, uint16_t /*crwTagId*/) {
Expand Down Expand Up @@ -672,7 +673,8 @@ void CrwMap::decode0x080a(const CiffComponent& ciffComponent, const CrwMapping*
void CrwMap::decodeArray(const CiffComponent& ciffComponent, const CrwMapping* pCrwMapping, Image& image,
ByteOrder byteOrder) {
if (ciffComponent.typeId() != unsignedShort) {
return decodeBasic(ciffComponent, pCrwMapping, image, byteOrder);
decodeBasic(ciffComponent, pCrwMapping, image, byteOrder);
return;
}

int64_t aperture = 0;
Expand Down Expand Up @@ -703,7 +705,7 @@ void CrwMap::decodeArray(const CiffComponent& ciffComponent, const CrwMapping* p
UShortValue value;
if (ifdId == IfdId::canonCsId && c == 23 && component_size >= 52)
n = 3;
value.read(ciffComponent.pData() + c * 2, n * 2, byteOrder);
value.read(ciffComponent.pData() + (c * 2), n * 2, byteOrder);
image.exifData().add(key, &value);
if (ifdId == IfdId::canonSiId && c == 21)
aperture = value.toInt64();
Expand Down Expand Up @@ -732,7 +734,8 @@ void CrwMap::decodeArray(const CiffComponent& ciffComponent, const CrwMapping* p
void CrwMap::decode0x180e(const CiffComponent& ciffComponent, const CrwMapping* pCrwMapping, Image& image,
ByteOrder byteOrder) {
if (ciffComponent.size() < 8 || ciffComponent.typeId() != unsignedLong) {
return decodeBasic(ciffComponent, pCrwMapping, image, byteOrder);
decodeBasic(ciffComponent, pCrwMapping, image, byteOrder);
return;
}
ULongValue v;
v.read(ciffComponent.pData(), 8, byteOrder);
Expand All @@ -758,7 +761,8 @@ void CrwMap::decode0x180e(const CiffComponent& ciffComponent, const CrwMapping*
void CrwMap::decode0x1810(const CiffComponent& ciffComponent, const CrwMapping* pCrwMapping, Image& image,
ByteOrder byteOrder) {
if (ciffComponent.typeId() != unsignedLong || ciffComponent.size() < 28) {
return decodeBasic(ciffComponent, pCrwMapping, image, byteOrder);
decodeBasic(ciffComponent, pCrwMapping, image, byteOrder);
return;
}

ExifKey key1("Exif.Photo.PixelXDimension");
Expand Down Expand Up @@ -997,17 +1001,16 @@ DataBuf packIfdId(const ExifData& exifData, IfdId ifdId, ByteOrder byteOrder) {
for (auto&& exif : exifData) {
if (exif.ifdId() != ifdId)
continue;
const uint16_t s = exif.tag() * 2 + static_cast<uint16_t>(exif.size());
const uint16_t s = (exif.tag() * 2) + static_cast<uint16_t>(exif.size());
if (s <= size) {
if (len < s)
len = s;
len = std::max(len, s);
exif.copy(buf.data(exif.tag() * 2), byteOrder);
} else {
EXV_ERROR << "packIfdId out-of-bounds error: s = " << std::dec << s << "\n";
}
}
// Round the size to make it even.
buf.resize(len + len % 2);
buf.resize(len + (len % 2));
return buf;
}

Expand Down
4 changes: 1 addition & 3 deletions src/epsimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,9 +1121,7 @@ bool isEpsType(BasicIo& iIo, bool advance) {
// read as many bytes as needed for the longest (DOS) EPS signature
size_t bufSize = dosEpsSignature.size();
for (auto&& i : epsFirstLine) {
if (bufSize < i.size()) {
bufSize = i.size();
}
bufSize = std::max(bufSize, i.size());
}
const size_t restore = iIo.tell(); // save
DataBuf buf = iIo.read(bufSize);
Expand Down
5 changes: 3 additions & 2 deletions src/helper_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

#include "helper_functions.hpp"

#include "convert.hpp"
#include "enforce.hpp"

#include <cmath>
#include <cstring>
#include <numeric>
#include "convert.hpp"
#include "enforce.hpp"

std::string string_from_unterminated(const char* data, size_t data_length) {
if (data_length == 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/helper_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#ifndef HELPER_FUNCTIONS_HPP
#define HELPER_FUNCTIONS_HPP

#include <string>
#include "basicio.hpp"
#include "types.hpp"

#include <string>

/*!
@brief Convert a (potentially not null terminated) array into a
std::string.
Expand Down
Loading