Skip to content

Commit

Permalink
various clang-tidy 19 fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Nov 23, 2024
1 parent 4cc15be commit c7ed664
Show file tree
Hide file tree
Showing 28 changed files with 73 additions and 75 deletions.
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
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
20 changes: 10 additions & 10 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 @@ -251,7 +252,7 @@ void CiffDirectory::readDirectory(const byte* pData, size_t size, ByteOrder byte
for (uint16_t i = 0; i < count; ++i) {
uint16_t tag = getUShort(pData + o, byteOrder);
auto m = [this, tag]() -> std::unique_ptr<CiffComponent> {
if (this->typeId(tag) == TypeId::directory)
if (Exiv2::Internal::CiffDirectory::typeId(tag) == TypeId::directory)
return std::make_unique<CiffDirectory>();
return std::make_unique<CiffEntry>();
}();
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,7 @@ 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 +704,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 +733,7 @@ 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 +759,7 @@ 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 +998,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
4 changes: 2 additions & 2 deletions src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "http.hpp"

#include <array>
#include <cerrno>
#include <chrono>
#include <cinttypes>
#include <thread>
Expand All @@ -25,7 +26,6 @@
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include <cerrno>

#define SOCKET_ERROR (-1)
#define WSAEWOULDBLOCK EINPROGRESS
Expand Down Expand Up @@ -226,7 +226,7 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
std::to_string(serv_addr.sin_port).c_str(), WSAGetLastError());
}

char buffer[32 * 1024 + 1];
char buffer[(32 * 1024) + 1];
size_t buff_l = sizeof buffer - 1;

////////////////////////////////////
Expand Down
8 changes: 4 additions & 4 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void Image::printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStruct
// if ( offset > io.size() ) offset = 0; // Denial of service?

// #55 and #56 memory allocation crash test/data/POC8
const size_t allocate64 = size * count + pad + 20;
const size_t allocate64 = (size * count) + pad + 20;
if (allocate64 > io.size()) {
throw Error(ErrorCode::kerInvalidMalloc);
}
Expand All @@ -436,7 +436,7 @@ void Image::printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStruct
}

if (bPrint) {
const size_t address = start + 2 + i * 12;
const size_t address = start + 2 + (i * 12);
const std::string offsetString = bOffsetIsPointer ? Internal::stringFormat("%10u", offset) : "";

out << Internal::indent(depth)
Expand All @@ -455,8 +455,8 @@ void Image::printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStruct

} else if (isRationalType(type)) {
for (size_t k = 0; k < kount; k++) {
uint32_t a = byteSwap4(buf, k * size + 0, bSwap);
uint32_t b = byteSwap4(buf, k * size + 4, bSwap);
uint32_t a = byteSwap4(buf, (k * size) + 0, bSwap);
uint32_t b = byteSwap4(buf, (k * size) + 4, bSwap);
out << sp << a << "/" << b;
sp = " ";
}
Expand Down
2 changes: 1 addition & 1 deletion src/jp2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ void Jp2Image::doWriteMetadata(BasicIo& outIo) {
}

// Prevent a malicious file from causing a large memory allocation.
Internal::enforce(box.length - 8 <= static_cast<size_t>(io_->size() - io_->tell()),
Internal::enforce(box.length - 8 <= io_->size() - io_->tell(),
ErrorCode::kerCorruptedMetadata);

// Read whole box : Box header + Box data (not fixed size - can be null).
Expand Down
2 changes: 1 addition & 1 deletion src/jp2image_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bool isValidBoxFileType(const std::vector<uint8_t>& boxData) {

bool clWithRightBrand = false;
for (size_t i = 0; i < N; i++) {
uint32_t compatibilityList = getULong(boxData.data() + 8 + i * 4, bigEndian);
uint32_t compatibilityList = getULong(boxData.data() + 8 + (i * 4), bigEndian);
if ((brand == brandJp2 && compatibilityList == brandJp2) || (brand == brandJph && compatibilityList == brandJph)) {
clWithRightBrand = true;
break;
Expand Down
4 changes: 2 additions & 2 deletions src/jpgimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,11 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
tmpBuf[0] = 0xff;
tmpBuf[1] = app2_;

const size_t chunk_size = 256 * 256 - 40; // leave bytes for marker, header and padding
const size_t chunk_size = (256 * 256) - 40; // leave bytes for marker, header and padding
size_t size = iccProfile_.size();
if (size >= 255 * chunk_size)
throw Error(ErrorCode::kerTooLargeJpegSegment, "IccProfile");
const size_t chunks = 1 + (size - 1) / chunk_size;
const size_t chunks = 1 + ((size - 1) / chunk_size);
for (size_t chunk = 0; chunk < chunks; chunk++) {
size_t bytes = size > chunk_size ? chunk_size : size; // bytes to write
size -= bytes;
Expand Down
Loading

0 comments on commit c7ed664

Please sign in to comment.