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

some clang-tidy #2198

Merged
merged 5 commits into from
Apr 10, 2022
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: 0 additions & 4 deletions samples/geotag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@

using namespace std;

#ifndef lengthof
#define lengthof(x) (sizeof(*x) / sizeof(x))
#endif

#if defined(_MSC_VER) || defined(__MINGW__)
#include <windows.h>
char* realpath(const char* file, char* path);
Expand Down
2 changes: 1 addition & 1 deletion samples/getopt-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#endif
#include <iostream>

#define Safe(x) (x ? x : "unknown")
#define Safe(x) ((x) ? (x) : "unknown")
const char* optstring = ":hVvqfbuktTFa:Y:O:D:r:p:P:d:e:i:c:m:M:l:S:g:K:n:Q:";

// *****************************************************************************
Expand Down
8 changes: 4 additions & 4 deletions src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#define WINAPI
using DWORD = unsigned long;

#define SOCKET_ERROR -1
#define SOCKET_ERROR (-1)
#define WSAEWOULDBLOCK EINPROGRESS
#define WSAENOTCONN EAGAIN

Expand All @@ -56,10 +56,10 @@ static constexpr auto httpTemplate =
"%s" // $header
"\r\n";

#define white(c) ((c == ' ') || (c == '\t'))
#define white(c) (((c) == ' ') || ((c) == '\t'))

#define FINISH -999
#define OK(s) (200 <= s && s < 300)
#define FINISH (-999)
#define OK(s) (200 <= (s) && (s) < 300)

static constexpr std::array<const char*, 2> blankLines{
"\r\n\r\n", // this is the standard
Expand Down
2 changes: 1 addition & 1 deletion src/jpgimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ DataBuf Photoshop::setIptcIrb(const byte* pPsData, size_t sizePsData, const Iptc

// Write existing stuff after record, skip the current and all remaining IPTC blocks
size_t pos = sizeFront;
long nextSizeData = Safe::add<long>(static_cast<long>(sizePsData), -static_cast<long>(pos));
auto nextSizeData = Safe::add<long>(static_cast<long>(sizePsData), -static_cast<long>(pos));
enforce(nextSizeData >= 0, ErrorCode::kerCorruptedMetadata);
while (0 == Photoshop::locateIptcIrb(pPsData + pos, nextSizeData, &record, &sizeHdr, &sizeIptc)) {
const auto newPos = static_cast<size_t>(record - pPsData);
Expand Down
26 changes: 12 additions & 14 deletions src/makernote_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ const TiffMnRegistry TiffMnCreator::registry_[] = {
{"-", pentaxId, nullptr, newPentaxMn2},
{"-", pentaxDngId, nullptr, newPentaxDngMn2},
{"-", casioId, nullptr, newIfdMn2},
{"-", casio2Id, nullptr, newCasio2Mn2}};
{"-", casio2Id, nullptr, newCasio2Mn2},
};

bool TiffMnRegistry::operator==(const std::string& key) const {
std::string make(make_);
Expand All @@ -131,25 +132,22 @@ bool TiffMnRegistry::operator==(IfdId key) const {

TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, const std::string& make, const byte* pData, size_t size,
ByteOrder byteOrder) {
TiffComponent* tc = nullptr;
const TiffMnRegistry* tmr = find(registry_, make);
if (tmr) {
tc = tmr->newMnFct_(tag, group, tmr->mnGroup_, pData, size, byteOrder);
auto tmr = std::find(std::begin(registry_), std::end(registry_), make);
if (tmr != std::end(registry_)) {
return tmr->newMnFct_(tag, group, tmr->mnGroup_, pData, size, byteOrder);
}
return tc;
return nullptr;
} // TiffMnCreator::create

TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, IfdId mnGroup) {
TiffComponent* tc = nullptr;
const TiffMnRegistry* tmr = find(registry_, mnGroup);
if (tmr) {
if (!tmr->newMnFct2_) {
std::cout << "mnGroup = " << mnGroup << "\n";
auto tmr = std::find(std::begin(registry_), std::end(registry_), mnGroup);
if (tmr != std::end(registry_)) {
if (tmr->newMnFct2_) {
return tmr->newMnFct2_(tag, group, mnGroup);
}

tc = tmr->newMnFct2_(tag, group, mnGroup);
std::cout << "mnGroup = " << mnGroup << "\n";
}
return tc;
return nullptr;
} // TiffMnCreator::create

void MnHeader::setByteOrder(ByteOrder /*byteOrder*/) {
Expand Down
2 changes: 1 addition & 1 deletion src/pngimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, in
const size_t imgSize = io_->size();
DataBuf cheaderBuf(8);

while (!io_->eof() && ::strcmp(chType, "IEND")) {
while (!io_->eof() && ::strcmp(chType, "IEND") != 0) {
size_t address = io_->tell();

size_t bufRead = io_->read(cheaderBuf.data(), cheaderBuf.size());
Expand Down
4 changes: 2 additions & 2 deletions src/tiffimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <iostream>

// Shortcuts for the newTiffBinaryArray templates.
#define EXV_BINARY_ARRAY(arrayCfg, arrayDef) (newTiffBinaryArray0<&arrayCfg, std::size(arrayDef), arrayDef>)
#define EXV_SIMPLE_BINARY_ARRAY(arrayCfg) (newTiffBinaryArray1<&arrayCfg>)
#define EXV_BINARY_ARRAY(arrayCfg, arrayDef) (newTiffBinaryArray0<&(arrayCfg), std::size(arrayDef), arrayDef>)
#define EXV_SIMPLE_BINARY_ARRAY(arrayCfg) (newTiffBinaryArray1<&(arrayCfg)>)
#define EXV_COMPLEX_BINARY_ARRAY(arraySet, cfgSelFct) (newTiffBinaryArray2<arraySet, std::size(arraySet), cfgSelFct>)

namespace Exiv2::Internal {
Expand Down
7 changes: 2 additions & 5 deletions src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#include <unistd.h>
#endif

#ifndef lengthof
#define lengthof(x) sizeof(x) / sizeof(x[0])
#endif
#ifndef _MAX_PATH
#define _MAX_PATH 512
#endif
Expand Down Expand Up @@ -126,10 +123,10 @@ static std::vector<std::string> getLoadedLibraries() {
// enumerate loaded libraries and determine path to executable
HMODULE handles[200];
DWORD cbNeeded;
if (EnumProcessModules(GetCurrentProcess(), handles, lengthof(handles), &cbNeeded)) {
if (EnumProcessModules(GetCurrentProcess(), handles, DWORD(std::size(handles)), &cbNeeded)) {
char szFilename[_MAX_PATH];
for (DWORD h = 0; h < cbNeeded / sizeof(handles[0]); h++) {
GetModuleFileNameA(handles[h], szFilename, lengthof(szFilename));
GetModuleFileNameA(handles[h], szFilename, DWORD(std::size(szFilename)));
std::string path(szFilename);
pushPath(path, libs, paths);
}
Expand Down