Skip to content

Commit 71dc04e

Browse files
committed
misc sonarlint stuff
Signed-off-by: Rosen Penev <[email protected]>
1 parent 89d7798 commit 71dc04e

14 files changed

+53
-46
lines changed

app/app_utils.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ namespace Util {
1414
bool strtol(const char* nptr, int64_t& n);
1515
} // namespace Util
1616

17-
#endif // #ifndef UTILS_HPP_
17+
#endif // APP_UTILS_HPP_

app/exiv2.cpp

+19-16
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,14 @@ int main(int argc, char* const argv[]) {
149149
std::cerr << params.progname() << ": " << _("Only one file is allowed when extracting to stdout") << std::endl;
150150
returnCode = EXIT_FAILURE;
151151
} else {
152-
int w = filesCount > 9 ? filesCount > 99 ? 3 : 2 : 1;
152+
int w = [=]() {
153+
if (filesCount > 9) {
154+
if (filesCount > 99)
155+
return 3;
156+
return 2;
157+
}
158+
return 1;
159+
}();
153160
int n = 1;
154161
for (const auto& file : params.files_) {
155162
// If extracting to stdout then ignore verbose
@@ -1038,19 +1045,15 @@ int Params::getopt(int argc, char* const Argv[]) {
10381045
std::cerr << progname() << ": " << _("At least one file is required\n");
10391046
rc = 1;
10401047
}
1041-
if (rc == 0 && !cmdFiles_.empty()) {
1042-
// Parse command files
1043-
if (!parseCmdFiles(modifyCmds_, cmdFiles_)) {
1044-
std::cerr << progname() << ": " << _("Error parsing -m option arguments\n");
1045-
rc = 1;
1046-
}
1048+
// Parse command files
1049+
if (rc == 0 && !cmdFiles_.empty() && !parseCmdFiles(modifyCmds_, cmdFiles_)) {
1050+
std::cerr << progname() << ": " << _("Error parsing -m option arguments\n");
1051+
rc = 1;
10471052
}
1048-
if (rc == 0 && !cmdLines_.empty()) {
1049-
// Parse command lines
1050-
if (!parseCmdLines(modifyCmds_, cmdLines_)) {
1051-
std::cerr << progname() << ": " << _("Error parsing -M option arguments\n");
1052-
rc = 1;
1053-
}
1053+
// Parse command lines
1054+
if (rc == 0 && !cmdLines_.empty() && !parseCmdLines(modifyCmds_, cmdLines_)) {
1055+
std::cerr << progname() << ": " << _("Error parsing -M option arguments\n");
1056+
rc = 1;
10541057
}
10551058
if (rc == 0 && (!cmdFiles_.empty() || !cmdLines_.empty())) {
10561059
// We'll set them again, after reading the file
@@ -1060,15 +1063,15 @@ int Params::getopt(int argc, char* const Argv[]) {
10601063
std::cerr << progname() << ": " << _("-l option can only be used with extract or insert actions\n");
10611064
rc = 1;
10621065
}
1063-
if (!suffix_.empty() && !(action_ == Action::insert)) {
1066+
if (!suffix_.empty() && action_ != Action::insert) {
10641067
std::cerr << progname() << ": " << _("-S option can only be used with insert action\n");
10651068
rc = 1;
10661069
}
1067-
if (timestamp_ && !(action_ == Action::rename)) {
1070+
if (timestamp_ && action_ != Action::rename) {
10681071
std::cerr << progname() << ": " << _("-t option can only be used with rename action\n");
10691072
rc = 1;
10701073
}
1071-
if (timestampOnly_ && !(action_ == Action::rename)) {
1074+
if (timestampOnly_ && action_ != Action::rename) {
10721075
std::cerr << progname() << ": " << _("-T option can only be used with rename action\n");
10731076
rc = 1;
10741077
}

app/getopt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int Getopt::getopt(int argc, char* const argv[], const std::string& optstring) {
8383
progname_ = fs::path(argv[0]).filename().string();
8484
Util::optind = 0; // reset the Util::Getopt scanner
8585

86-
for (; !errcnt_;) {
86+
while (!errcnt_) {
8787
int c = Util::getopt(argc, argv, optstring.c_str());
8888
if (c == -1) {
8989
break;

include/exiv2/bmffimage.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class EXIV2API BmffImage : public Image {
141141
std::string boxName(uint32_t box);
142142
static bool superBox(uint32_t box);
143143
static bool fullBox(uint32_t box);
144-
static std::string uuidName(Exiv2::DataBuf& uuid);
144+
static std::string uuidName(const Exiv2::DataBuf& uuid);
145145

146146
}; // class BmffImage
147147

src/bmffimage.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ std::string BmffImage::toAscii(uint32_t n) {
7979
std::string result;
8080
for (int i = 0; i < 4; i++) {
8181
char c = p[isBigEndianPlatform() ? i : (3 - i)];
82-
result += (32 <= c && c < 127) ? c // only allow 7-bit printable ascii
83-
: c == 0 ? '_' // show 0 as _
84-
: '.'; // others .
82+
result += [c]() {
83+
if (32 <= c && c < 127)
84+
return c; // only allow 7-bit printable ascii
85+
if (c == 0)
86+
return '_'; // show 0 as _
87+
return '.'; // others .
88+
}();
8589
}
8690
return result;
8791
}
@@ -141,7 +145,7 @@ uint32_t BmffImage::pixelHeight() const {
141145
return pixelHeight_;
142146
}
143147

144-
std::string BmffImage::uuidName(Exiv2::DataBuf& uuid) {
148+
std::string BmffImage::uuidName(const Exiv2::DataBuf& uuid) {
145149
const char* uuidCano = "\x85\xC0\xB6\x87\x82\xF\x11\xE0\x81\x11\xF4\xCE\x46\x2B\x6A\x48";
146150
const char* uuidXmp = "\xBE\x7A\xCF\xCB\x97\xA9\x42\xE8\x9C\x71\x99\x94\x91\xE3\xAF\xAC";
147151
const char* uuidCanp = "\xEA\xF4\x2B\x5E\x1C\x98\x4B\x88\xB9\xFB\xB7\xDC\x40\x6E\x4D\x16";

src/canonmn_int.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
07-Mar-04, ahu: isolated as a separate component<BR>
1313
12-Aug-06, dc: started updating all tags
1414
*/
15-
#ifndef CANONMN_INT_HPP_
16-
#define CANONMN_INT_HPP_
15+
#ifndef EXIV2_CANONMN_INT_HPP
16+
#define EXIV2_CANONMN_INT_HPP
1717

1818
// *****************************************************************************
1919
// included header files
@@ -201,4 +201,4 @@ float canonEv(int64_t val);
201201

202202
} // namespace Exiv2::Internal
203203

204-
#endif // #ifndef CANONMN_INT_HPP_
204+
#endif // EXIV2_CANONMN_INT_HPP

src/casiomn_int.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
Specification</a> by Evan Hunter.
1010
@date 30-Oct-13, ahu: created
1111
*/
12-
#ifndef CASIOMN_INT_HPP_
13-
#define CASIOMN_INT_HPP_
12+
#ifndef EXIV2_CASIOMN_INT_HPP
13+
#define EXIV2_CASIOMN_INT_HPP
1414

1515
// *****************************************************************************
1616
// included header files
@@ -57,4 +57,4 @@ class Casio2MakerNote {
5757

5858
} // namespace Exiv2::Internal
5959

60-
#endif // #ifndef CasioMN_INT_HPP_
60+
#endif // EXIV2_CASIOMN_INT_HPP

src/convert.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ std::string Converter::computeExifDigest(bool tiff) {
12761276
MD5Final(digest, &context);
12771277
res << ';';
12781278
res << std::setw(2) << std::setfill('0') << std::hex << std::uppercase;
1279-
for (auto&& i : digest) {
1279+
for (const auto& i : digest) {
12801280
res << static_cast<int>(i);
12811281
}
12821282
return res.str();

src/cr2header_int.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
88
@date 23-Apr-08, ahu: created
99
*/
10-
#ifndef CR2IMAGE_INT_HPP_
11-
#define CR2IMAGE_INT_HPP_
10+
#ifndef EXIV2_CR2HEADER_INT_HPP
11+
#define EXIV2_CR2HEADER_INT_HPP
1212

1313
// *****************************************************************************
1414
// included header files
@@ -55,4 +55,4 @@ class Cr2Header : public TiffHeaderBase {
5555

5656
} // namespace Exiv2::Internal
5757

58-
#endif // #ifndef CR2IMAGE_INT_HPP_
58+
#endif // EXIV2_CR2HEADER_INT_HPP

src/crwimage_int.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22

3-
#ifndef CRWIMAGE_INT_HPP_
4-
#define CRWIMAGE_INT_HPP_
3+
#ifndef EXIV2_CRWIMAGE_INT_HPP
4+
#define EXIV2_CRWIMAGE_INT_HPP
55

66
// *****************************************************************************
77
// included header files
@@ -656,4 +656,4 @@ DataBuf packIfdId(const ExifData& exifData, IfdId ifdId, ByteOrder byteOrder);
656656

657657
} // namespace Exiv2::Internal
658658

659-
#endif // #ifndef CRWIMAGE_INT_HPP_
659+
#endif // EXIV2_CRWIMAGE_INT_HPP

src/epsimage.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
828828
if (useFlexibleEmbedding) {
829829
positions.push_back(xmpPos);
830830
}
831-
for (auto&& [r, s] : removableEmbeddings) {
831+
for (const auto& [r, s] : removableEmbeddings) {
832832
positions.push_back(r);
833833
}
834834
std::sort(positions.begin(), positions.end());
@@ -842,7 +842,7 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
842842
const uint32_t posEpsNew = posTemp(tempIo);
843843
size_t prevPos = posEps;
844844
size_t prevSkipPos = prevPos;
845-
for (auto&& pos : positions) {
845+
for (const auto& pos : positions) {
846846
if (pos == prevPos)
847847
continue;
848848
#ifdef DEBUG
@@ -937,7 +937,7 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
937937
}
938938
if (!useFlexibleEmbedding) {
939939
// remove preceding embedding(s)
940-
for (auto&& [p, s] : removableEmbeddings) {
940+
for (const auto& [p, s] : removableEmbeddings) {
941941
if (pos == p) {
942942
skipPos = s;
943943
#ifdef DEBUG

src/futils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Protocol fileProtocol(const std::string& path) {
201201
} prots[] = {{"http://", pHttp, true}, {"https://", pHttps, true}, {"ftp://", pFtp, true},
202202
{"sftp://", pSftp, true}, {"file://", pFileUri, true}, {"data://", pDataUri, true},
203203
{"-", pStdin, false}};
204-
for (auto&& prot : prots) {
204+
for (const auto& prot : prots) {
205205
if (result != pFile)
206206
break;
207207

src/http.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
177177
const char* NO_PROXY = getenv(NO_PROXI);
178178
const char* no_proxy = getenv(no_proxi);
179179
bool bNoProxy = NO_PROXY || no_proxy;
180-
std::string no_prox = std::string(bNoProxy ? (no_proxy ? no_proxy : NO_PROXY) : "");
180+
auto no_prox = std::string(bNoProxy ? (no_proxy ? no_proxy : NO_PROXY) : "");
181181
Exiv2::Dictionary noProxy = stringToDict(no_prox + ",localhost,127.0.0.1");
182182

183183
// if the server is on the no_proxy list ... ignore the proxy!
@@ -214,7 +214,7 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
214214
// convert unknown servername into IP address
215215
// http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/rzab6/rzab6uafinet.htm
216216
if (serv_addr.sin_addr.s_addr == static_cast<unsigned long>(INADDR_NONE)) {
217-
struct hostent* host = gethostbyname(servername_p);
217+
auto host = gethostbyname(servername_p);
218218
if (!host)
219219
return error(errors, "no such host", servername_p);
220220
memcpy(&serv_addr.sin_addr, host->h_addr, sizeof(serv_addr.sin_addr));
@@ -300,7 +300,7 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
300300
break;
301301
}
302302
result = atoi(firstSpace);
303-
char* c = strchr(h, C);
303+
auto c = strchr(h, C);
304304
char* first_newline = strchr(h, N);
305305
while (c && first_newline && c < first_newline && h < buffer + body) {
306306
std::string key(h);

src/makernote_int.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22

3-
#ifndef MAKERNOTE_INT_HPP_
4-
#define MAKERNOTE_INT_HPP_
3+
#ifndef EXIV2_MAKERNOTE_INT_HPP
4+
#define EXIV2_MAKERNOTE_INT_HPP
55

66
// *****************************************************************************
77
// included header files
@@ -700,4 +700,4 @@ DataBuf nikonCrypt(uint16_t tag, const byte* pData, size_t size, TiffComponent*
700700

701701
} // namespace Exiv2::Internal
702702

703-
#endif // #ifndef MAKERNOTE_INT_HPP_
703+
#endif // EXIV2_MAKERNOTE_INT_HPP

0 commit comments

Comments
 (0)