Skip to content

Commit 22b1201

Browse files
committed
more SonarLint cleanups
Signed-off-by: Rosen Penev <[email protected]>
1 parent d29001f commit 22b1201

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+254
-301
lines changed

app/exiv2.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,9 @@ int Params::getopt(int argc, char* const Argv[]) {
10921092
// local implementations
10931093
namespace {
10941094
bool parseTime(const std::string& ts, int64_t& time) {
1095-
std::string hstr, mstr, sstr;
1095+
std::string hstr;
1096+
std::string mstr;
1097+
std::string sstr;
10961098
auto cts = new char[ts.length() + 1];
10971099
strcpy(cts, ts.c_str());
10981100
auto tmp = ::strtok(cts, ":");
@@ -1107,7 +1109,9 @@ bool parseTime(const std::string& ts, int64_t& time) {
11071109
delete[] cts;
11081110

11091111
int sign = 1;
1110-
int64_t hh(0), mm(0), ss(0);
1112+
int64_t hh = 0;
1113+
int64_t mm = 0;
1114+
int64_t ss = 0;
11111115
// [-]HH part
11121116
if (!Util::strtol(hstr.c_str(), hh))
11131117
return false;

include/exiv2/iptc.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class EXIV2API IptcData {
177177
@return 0 if successful;<BR>
178178
6 if the dataset already exists and is not repeatable
179179
*/
180-
int add(const IptcKey& key, Value* value);
180+
int add(const IptcKey& key, const Value* value);
181181
/*!
182182
@brief Add a copy of the Iptcdatum to the IPTC metadata. A check
183183
for non-repeatable datasets is performed.
@@ -244,7 +244,7 @@ class EXIV2API IptcData {
244244
[[nodiscard]] const_iterator findId(uint16_t dataset, uint16_t record = IptcDataSets::application2) const;
245245
//! Return true if there is no IPTC metadata
246246
[[nodiscard]] bool empty() const {
247-
return count() == 0;
247+
return iptcMetadata_.empty();
248248
}
249249

250250
//! Get the number of metadata entries

include/exiv2/quicktimevideo.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ class EXIV2API QuickTimeVideo : public Image {
200200
//! Variable to check the end of metadata traversing.
201201
bool continueTraversing_ = false;
202202
//! Variable to store height and width of a video frame.
203-
uint64_t height_ = 0, width_ = 0;
203+
uint64_t height_ = 0;
204+
uint64_t width_ = 0;
204205

205206
}; // QuickTimeVideo End
206207

include/exiv2/riffvideo.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class EXIV2API RiffVideo : public Image {
4848
uint64_t size_ = 0;
4949

5050
public:
51-
explicit HeaderReader(BasicIo::UniquePtr& io);
51+
explicit HeaderReader(const BasicIo::UniquePtr& io);
5252

5353
[[nodiscard]] uint64_t getSize() const {
5454
return size_;
@@ -59,9 +59,9 @@ class EXIV2API RiffVideo : public Image {
5959
}
6060
};
6161

62-
void readList(HeaderReader& header_);
62+
void readList(const HeaderReader& header_);
6363

64-
void readChunk(HeaderReader& header_);
64+
void readChunk(const HeaderReader& header_);
6565

6666
void decodeBlocks();
6767

include/exiv2/slice.hpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ struct SliceBase {
4848
* lower and upper bounds of the slice with respect to the
4949
* container/array stored in storage_
5050
*/
51-
const size_t begin_, end_;
51+
size_t begin_;
52+
size_t end_;
5253
};
5354

5455
/*!
@@ -260,10 +261,13 @@ struct MutableSliceBase : public ConstSliceBase<storage_type, data_type> {
260261
template <typename container>
261262
struct ContainerStorage {
262263
using iterator = typename container::iterator;
263-
264264
using const_iterator = typename container::const_iterator;
265265

266+
#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
267+
using value_type = std::remove_cv_t<typename container::value_type>;
268+
#else
266269
using value_type = typename std::remove_cv<typename container::value_type>::type;
270+
#endif
267271

268272
/*!
269273
* @throw std::out_of_range when end is larger than the container's
@@ -324,7 +328,11 @@ struct ContainerStorage {
324328
*/
325329
template <typename storage_type>
326330
struct PtrSliceStorage {
331+
#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
332+
using value_type = std::remove_cv_t<std::remove_pointer_t<storage_type>>;
333+
#else
327334
using value_type = typename std::remove_cv<typename std::remove_pointer<storage_type>::type>::type;
335+
#endif
328336
using iterator = value_type*;
329337
using const_iterator = const value_type*;
330338

@@ -423,7 +431,11 @@ struct Slice : public Internal::MutableSliceBase<Internal::ContainerStorage, con
423431

424432
using const_iterator = typename container::const_iterator;
425433

434+
#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
435+
using value_type = std::remove_cv_t<typename container::value_type>;
436+
#else
426437
using value_type = typename std::remove_cv<typename container::value_type>::type;
438+
#endif
427439

428440
/*!
429441
* @brief Construct a slice of the container `cont` starting at `begin`
@@ -476,7 +488,11 @@ struct Slice<const container> : public Internal::ConstSliceBase<Internal::Contai
476488

477489
using const_iterator = typename container::const_iterator;
478490

491+
#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
492+
using value_type = std::remove_cv_t<typename container::value_type>;
493+
#else
479494
using value_type = typename std::remove_cv<typename container::value_type>::type;
495+
#endif
480496

481497
Slice(const container& cont, size_t begin, size_t end) :
482498
Internal::ConstSliceBase<Internal::ContainerStorage, const container>(cont, begin, end) {

include/exiv2/value.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,9 +1502,8 @@ template <typename T>
15021502
int ValueType<T>::read(const byte* buf, size_t len, ByteOrder byteOrder) {
15031503
value_.clear();
15041504
size_t ts = TypeInfo::typeSize(typeId());
1505-
if (ts > 0)
1506-
if (len % ts != 0)
1507-
len = (len / ts) * ts;
1505+
if (ts > 0 && len % ts != 0)
1506+
len = (len / ts) * ts;
15081507
for (size_t i = 0; i < len; i += ts) {
15091508
value_.push_back(getValue<T>(buf + i, byteOrder));
15101509
}

src/asfvideo.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -362,22 +362,22 @@ void AsfVideo::DegradableJPEGMedia() {
362362
void AsfVideo::streamProperties() {
363363
DataBuf streamTypedBuf = io_->read(GUID);
364364

365-
enum streamTypeInfo { Audio = 1, Video = 2 };
366-
int stream = 0;
365+
enum class streamTypeInfo { Audio = 1, Video = 2 };
366+
auto stream = static_cast<streamTypeInfo>(0);
367367

368368
auto tag_stream_type = GUIDReferenceTags.find(GUIDTag(streamTypedBuf.data()));
369369
if (tag_stream_type != GUIDReferenceTags.end()) {
370370
if (tag_stream_type->second == "Audio_Media")
371-
stream = Audio;
371+
stream = streamTypeInfo::Audio;
372372
else if (tag_stream_type->second == "Video_Media")
373-
stream = Video;
373+
stream = streamTypeInfo::Video;
374374

375375
io_->seek(io_->tell() + GUID, BasicIo::beg); // ignore Error Correction Type
376376

377377
uint64_t time_offset = readQWORDTag(io_);
378-
if (stream == Video)
378+
if (stream == streamTypeInfo::Video)
379379
xmpData()["Xmp.video.TimeOffset"] = time_offset;
380-
else if (stream == Audio)
380+
else if (stream == streamTypeInfo::Audio)
381381
xmpData()["Xmp.audio.TimeOffset"] = time_offset;
382382

383383
auto specific_data_length = readDWORDTag(io_);
@@ -396,12 +396,10 @@ void AsfVideo::codecList() {
396396
uint16_t codec_type = readWORDTag(io_) * 2;
397397
std::string codec = (codec_type == 1) ? "Xmp.video" : "Xmp.audio";
398398

399-
uint16_t codec_name_length = readWORDTag(io_) * 2;
400-
if (codec_name_length)
399+
if (uint16_t codec_name_length = readWORDTag(io_) * 2)
401400
xmpData()[codec + std::string(".CodecName")] = readStringWcharTag(io_, codec_name_length);
402401

403-
uint16_t codec_desc_length = readWORDTag(io_);
404-
if (codec_desc_length)
402+
if (uint16_t codec_desc_length = readWORDTag(io_))
405403
xmpData()[codec + std::string(".CodecDescription")] = readStringWcharTag(io_, codec_desc_length);
406404

407405
uint16_t codec_info_length = readWORDTag(io_);
@@ -422,13 +420,11 @@ void AsfVideo::extendedContentDescription() {
422420
std::string value;
423421

424422
for (uint16_t i = 0; i < content_descriptor_count; i++) {
425-
uint16_t descriptor_name_length = readWORDTag(io_);
426-
if (descriptor_name_length)
423+
if (uint16_t descriptor_name_length = readWORDTag(io_))
427424
value += readStringWcharTag(io_, descriptor_name_length); // Descriptor Name
428425

429426
uint16_t descriptor_value_data_type = readWORDTag(io_);
430-
uint16_t descriptor_value_length = readWORDTag(io_);
431-
if (descriptor_value_length) {
427+
if (uint16_t descriptor_value_length = readWORDTag(io_)) {
432428
// Descriptor Value
433429
switch (descriptor_value_data_type) {
434430
case 0 /*Unicode string */:
@@ -448,7 +444,6 @@ void AsfVideo::extendedContentDescription() {
448444
break;
449445
case 5 /*WORD*/:
450446
value += std::string(": ") + std::to_string(readWORDTag(io_));
451-
;
452447
break;
453448
}
454449
}

src/basicio.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ int FileIo::Impl::switchMode(OpMode opMode) {
159159
}
160160

161161
// Reopen the file
162-
long offset = std::ftell(fp_);
162+
#ifdef _WIN32
163+
auto offset = _ftelli64(fp_);
164+
#else
165+
auto offset = ftello(fp_);
166+
#endif
163167
if (offset == -1)
164168
return -1;
165169
// 'Manual' open("r+b") to avoid munmap()
@@ -172,7 +176,11 @@ int FileIo::Impl::switchMode(OpMode opMode) {
172176
fp_ = std::fopen(path_.c_str(), openMode_.c_str());
173177
if (!fp_)
174178
return 1;
175-
return std::fseek(fp_, offset, SEEK_SET);
179+
#ifdef _WIN32
180+
return _fseeki64(fp_, offset, SEEK_SET);
181+
#else
182+
return fseeko(fp_, offset, SEEK_SET);
183+
#endif
176184
} // FileIo::Impl::switchMode
177185

178186
int FileIo::Impl::stat(StructStat& buf) const {
@@ -460,15 +468,19 @@ int FileIo::seek(int64_t offset, Position pos) {
460468

461469
if (p_->switchMode(Impl::opSeek) != 0)
462470
return 1;
463-
#ifdef _WIN64
471+
#ifdef _WIN32
464472
return _fseeki64(p_->fp_, offset, fileSeek);
465473
#else
466-
return std::fseek(p_->fp_, static_cast<long>(offset), fileSeek);
474+
return fseeko(p_->fp_, offset, fileSeek);
467475
#endif
468476
}
469477

470478
size_t FileIo::tell() const {
471-
const long pos = std::ftell(p_->fp_);
479+
#ifdef _WIN32
480+
auto pos = _ftelli64(p_->fp_);
481+
#else
482+
auto pos = ftello(p_->fp_);
483+
#endif
472484
Internal::enforce(pos >= 0, ErrorCode::kerInputDataReadFailed);
473485
return static_cast<size_t>(pos);
474486
}
@@ -1069,7 +1081,8 @@ size_t RemoteIo::Impl::populateBlocks(size_t lowBlock, size_t highBlock) {
10691081
throw Error(ErrorCode::kerErrorMessage, "Data By Range is empty. Please check the permission.");
10701082
}
10711083
auto source = reinterpret_cast<byte*>(const_cast<char*>(data.c_str()));
1072-
size_t remain = rcount, totalRead = 0;
1084+
size_t remain = rcount;
1085+
size_t totalRead = 0;
10731086
size_t iBlock = (rcount == size_) ? 0 : lowBlock;
10741087

10751088
while (remain) {
@@ -1109,7 +1122,9 @@ int RemoteIo::open() {
11091122
p_->blocksMap_ = new BlockMap[nBlocks];
11101123
p_->isMalloced_ = true;
11111124
auto source = reinterpret_cast<byte*>(const_cast<char*>(data.c_str()));
1112-
size_t remain = p_->size_, iBlock = 0, totalRead = 0;
1125+
size_t remain = p_->size_;
1126+
size_t iBlock = 0;
1127+
size_t totalRead = 0;
11131128
while (remain) {
11141129
auto allow = std::min<size_t>(remain, p_->blockSize_);
11151130
p_->blocksMap_[iBlock].populate(&source[totalRead], allow);
@@ -1465,8 +1480,7 @@ void HttpIo::HttpImpl::writeRemote(const byte* data, size_t size, size_t from, s
14651480
}
14661481

14671482
// standardize the path without "/" at the beginning.
1468-
std::size_t protocolIndex = scriptPath.find("://");
1469-
if (protocolIndex == std::string::npos && scriptPath.front() != '/') {
1483+
if (scriptPath.find("://") == std::string::npos && scriptPath.front() != '/') {
14701484
scriptPath = "/" + scriptPath;
14711485
}
14721486

@@ -1651,8 +1665,7 @@ void CurlIo::CurlImpl::writeRemote(const byte* data, size_t size, size_t from, s
16511665
Exiv2::Uri hostInfo = Exiv2::Uri::Parse(path_);
16521666

16531667
// add the protocol and host to the path
1654-
std::size_t protocolIndex = scriptPath.find("://");
1655-
if (protocolIndex == std::string::npos) {
1668+
if (scriptPath.find("://") == std::string::npos) {
16561669
if (scriptPath.front() != '/')
16571670
scriptPath = "/" + scriptPath;
16581671
scriptPath = hostInfo.Protocol + "://" + hostInfo.Host + scriptPath;

src/bmffimage.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,16 @@ std::string BmffImage::mimeType() const {
137137

138138
uint32_t BmffImage::pixelWidth() const {
139139
auto imageWidth = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelXDimension"));
140-
if (imageWidth != exifData_.end() && imageWidth->count() > 0) {
141-
return imageWidth->toUint32();
142-
}
143-
return pixelWidth_;
140+
if (imageWidth == exifData_.end() || imageWidth->count() == 0)
141+
return pixelWidth_;
142+
return imageWidth->toUint32();
144143
}
145144

146145
uint32_t BmffImage::pixelHeight() const {
147146
auto imageHeight = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelYDimension"));
148-
if (imageHeight != exifData_.end() && imageHeight->count() > 0) {
149-
return imageHeight->toUint32();
150-
}
151-
return pixelHeight_;
147+
if (imageHeight == exifData_.end() || imageHeight->count() == 0)
148+
return pixelHeight_;
149+
return imageHeight->toUint32();
152150
}
153151

154152
std::string BmffImage::uuidName(const Exiv2::DataBuf& uuid) {
@@ -254,13 +252,13 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
254252

255253
size_t hdrsize = sizeof(hdrbuf);
256254
Internal::enforce(hdrsize <= static_cast<size_t>(pbox_end - address), Exiv2::ErrorCode::kerCorruptedMetadata);
257-
if (io_->read(reinterpret_cast<byte*>(&hdrbuf), sizeof(hdrbuf)) != sizeof(hdrbuf))
255+
if (io_->read(hdrbuf, sizeof(hdrbuf)) != sizeof(hdrbuf))
258256
return pbox_end;
259257

260258
// The box length is encoded as a uint32_t by default, but the special value 1 means
261259
// that it's a uint64_t.
262-
uint64_t box_length = getULong(reinterpret_cast<byte*>(&hdrbuf[0]), endian_);
263-
uint32_t box_type = getULong(reinterpret_cast<byte*>(&hdrbuf[sizeof(uint32_t)]), endian_);
260+
uint64_t box_length = getULong(&hdrbuf[0], endian_);
261+
uint32_t box_type = getULong(&hdrbuf[sizeof(uint32_t)], endian_);
264262
bool bLF = true;
265263

266264
if (bTrace) {

0 commit comments

Comments
 (0)