Skip to content

Commit 053f516

Browse files
authored
Merge pull request #2198 from neheb/3
some clang-tidy
2 parents fdfcde5 + 89b8d4e commit 053f516

File tree

8 files changed

+23
-32
lines changed

8 files changed

+23
-32
lines changed

samples/geotag.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919

2020
using namespace std;
2121

22-
#ifndef lengthof
23-
#define lengthof(x) (sizeof(*x) / sizeof(x))
24-
#endif
25-
2622
#if defined(_MSC_VER) || defined(__MINGW__)
2723
#include <windows.h>
2824
char* realpath(const char* file, char* path);

samples/getopt-test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#endif
3232
#include <iostream>
3333

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

3737
// *****************************************************************************

src/http.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#define WINAPI
3838
using DWORD = unsigned long;
3939

40-
#define SOCKET_ERROR -1
40+
#define SOCKET_ERROR (-1)
4141
#define WSAEWOULDBLOCK EINPROGRESS
4242
#define WSAENOTCONN EAGAIN
4343

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

59-
#define white(c) ((c == ' ') || (c == '\t'))
59+
#define white(c) (((c) == ' ') || ((c) == '\t'))
6060

61-
#define FINISH -999
62-
#define OK(s) (200 <= s && s < 300)
61+
#define FINISH (-999)
62+
#define OK(s) (200 <= (s) && (s) < 300)
6363

6464
static constexpr std::array<const char*, 2> blankLines{
6565
"\r\n\r\n", // this is the standard

src/jpgimage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ DataBuf Photoshop::setIptcIrb(const byte* pPsData, size_t sizePsData, const Iptc
181181

182182
// Write existing stuff after record, skip the current and all remaining IPTC blocks
183183
size_t pos = sizeFront;
184-
long nextSizeData = Safe::add<long>(static_cast<long>(sizePsData), -static_cast<long>(pos));
184+
auto nextSizeData = Safe::add<long>(static_cast<long>(sizePsData), -static_cast<long>(pos));
185185
enforce(nextSizeData >= 0, ErrorCode::kerCorruptedMetadata);
186186
while (0 == Photoshop::locateIptcIrb(pPsData + pos, nextSizeData, &record, &sizeHdr, &sizeIptc)) {
187187
const auto newPos = static_cast<size_t>(record - pPsData);

src/makernote_int.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ const TiffMnRegistry TiffMnCreator::registry_[] = {
116116
{"-", pentaxId, nullptr, newPentaxMn2},
117117
{"-", pentaxDngId, nullptr, newPentaxDngMn2},
118118
{"-", casioId, nullptr, newIfdMn2},
119-
{"-", casio2Id, nullptr, newCasio2Mn2}};
119+
{"-", casio2Id, nullptr, newCasio2Mn2},
120+
};
120121

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

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

142142
TiffComponent* TiffMnCreator::create(uint16_t tag, IfdId group, IfdId mnGroup) {
143-
TiffComponent* tc = nullptr;
144-
const TiffMnRegistry* tmr = find(registry_, mnGroup);
145-
if (tmr) {
146-
if (!tmr->newMnFct2_) {
147-
std::cout << "mnGroup = " << mnGroup << "\n";
143+
auto tmr = std::find(std::begin(registry_), std::end(registry_), mnGroup);
144+
if (tmr != std::end(registry_)) {
145+
if (tmr->newMnFct2_) {
146+
return tmr->newMnFct2_(tag, group, mnGroup);
148147
}
149-
150-
tc = tmr->newMnFct2_(tag, group, mnGroup);
148+
std::cout << "mnGroup = " << mnGroup << "\n";
151149
}
152-
return tc;
150+
return nullptr;
153151
} // TiffMnCreator::create
154152

155153
void MnHeader::setByteOrder(ByteOrder /*byteOrder*/) {

src/pngimage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, in
210210
const size_t imgSize = io_->size();
211211
DataBuf cheaderBuf(8);
212212

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

216216
size_t bufRead = io_->read(cheaderBuf.data(), cheaderBuf.size());

src/tiffimage_int.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <iostream>
1313

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

1919
namespace Exiv2::Internal {

src/version.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
#include <unistd.h>
2828
#endif
2929

30-
#ifndef lengthof
31-
#define lengthof(x) sizeof(x) / sizeof(x[0])
32-
#endif
3330
#ifndef _MAX_PATH
3431
#define _MAX_PATH 512
3532
#endif
@@ -126,10 +123,10 @@ static std::vector<std::string> getLoadedLibraries() {
126123
// enumerate loaded libraries and determine path to executable
127124
HMODULE handles[200];
128125
DWORD cbNeeded;
129-
if (EnumProcessModules(GetCurrentProcess(), handles, lengthof(handles), &cbNeeded)) {
126+
if (EnumProcessModules(GetCurrentProcess(), handles, DWORD(std::size(handles)), &cbNeeded)) {
130127
char szFilename[_MAX_PATH];
131128
for (DWORD h = 0; h < cbNeeded / sizeof(handles[0]); h++) {
132-
GetModuleFileNameA(handles[h], szFilename, lengthof(szFilename));
129+
GetModuleFileNameA(handles[h], szFilename, DWORD(std::size(szFilename)));
133130
std::string path(szFilename);
134131
pushPath(path, libs, paths);
135132
}

0 commit comments

Comments
 (0)