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 sonarlint cleanups #2286

Merged
merged 7 commits into from
Jul 27, 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
9 changes: 5 additions & 4 deletions app/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
#include <utime.h>
#endif

#if !defined(__MINGW__) && !defined(_MSC_VER)
#define _fileno(a) a
#define _setmode(a, b)
#ifndef _WIN32
#define _setmode(a, b) \
do { \
} while (false)
#endif

namespace fs = std::filesystem;
Expand Down Expand Up @@ -1666,7 +1667,7 @@ std::string tm2Str(const struct tm* tm) {

std::string temporaryPath() {
static int count = 0;
std::lock_guard<std::mutex> guard(cs);
auto guard = std::scoped_lock(cs);

#if defined(_MSC_VER) || defined(__MINGW__)
HANDLE process = 0;
Expand Down
8 changes: 4 additions & 4 deletions app/exiv2app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ enum class MetadataId : uint32_t {
};

inline MetadataId operator&(MetadataId x, MetadataId y) {
return (MetadataId)(uint32_t(x) & uint32_t(y));
return static_cast<MetadataId>(static_cast<uint32_t>(x) & static_cast<uint32_t>(y));
}

inline MetadataId operator|(MetadataId x, MetadataId y) {
return (MetadataId)(uint32_t(x) | uint32_t(y));
return static_cast<MetadataId>(static_cast<uint32_t>(x) | static_cast<uint32_t>(y));
}

inline MetadataId& operator|=(MetadataId& x, MetadataId y) {
Expand Down Expand Up @@ -286,15 +286,15 @@ class Params : public Util::Getopt {
}; // class Params

inline Params::CommonTarget operator|(Params::CommonTarget x, Params::CommonTarget y) {
return (Params::CommonTarget)(uint32_t(x) | uint32_t(y));
return static_cast<Params::CommonTarget>(static_cast<uint32_t>(x) | static_cast<uint32_t>(y));
}

inline Params::CommonTarget& operator|=(Params::CommonTarget& x, Params::CommonTarget y) {
return x = x | y;
}

inline Params::PrintItem operator|(Params::PrintItem x, Params::PrintItem y) {
return (Params::PrintItem)(uint32_t(x) | uint32_t(y));
return static_cast<Params::PrintItem>(static_cast<uint32_t>(x) | static_cast<uint32_t>(y));
}

inline Params::PrintItem& operator|=(Params::PrintItem& x, Params::PrintItem y) {
Expand Down
4 changes: 2 additions & 2 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ void HttpIo::HttpImpl::writeRemote(const byte* data, size_t size, size_t from, s

// standardize the path without "/" at the beginning.
std::size_t protocolIndex = scriptPath.find("://");
if (protocolIndex == std::string::npos && scriptPath[0] != '/') {
if (protocolIndex == std::string::npos && scriptPath.front() != '/') {
scriptPath = "/" + scriptPath;
}

Expand Down Expand Up @@ -1657,7 +1657,7 @@ void CurlIo::CurlImpl::writeRemote(const byte* data, size_t size, size_t from, s
// add the protocol and host to the path
std::size_t protocolIndex = scriptPath.find("://");
if (protocolIndex == std::string::npos) {
if (scriptPath[0] != '/')
if (scriptPath.front() != '/')
scriptPath = "/" + scriptPath;
scriptPath = hostInfo.Protocol + "://" + hostInfo.Host + scriptPath;
}
Expand Down
9 changes: 5 additions & 4 deletions src/epsimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
#endif
// implicit comments
if (line == "%%EOF" || line == "%begin_xml_code" ||
!(line.size() >= 2 && line[0] == '%' && '\x21' <= line[1] && line[1] <= '\x7e')) {
!(line.size() >= 2 && line.front() == '%' && '\x21' <= line[1] && line[1] <= '\x7e')) {
if (posEndComments == posEndEps) {
posEndComments = startPos;
#ifdef DEBUG
Expand All @@ -492,20 +492,21 @@ void readWriteEpsMetadata(BasicIo& io, std::string& xmpPacket, NativePreviewList
#endif
}
if (posBeginPageSetup == posEndEps &&
(implicitPage || (posPage != posEndEps && !inRemovableEmbedding && !line.empty() && line[0] != '%'))) {
(implicitPage || (posPage != posEndEps && !inRemovableEmbedding && !line.empty() && line.front() != '%'))) {
posBeginPageSetup = startPos;
implicitPageSetup = true;
#ifdef DEBUG
EXV_DEBUG << "readWriteEpsMetadata: Found implicit BeginPageSetup at position: " << startPos << "\n";
#endif
}
if (posEndPageSetup == posEndEps && implicitPageSetup && !inRemovableEmbedding && !line.empty() && line[0] != '%') {
if (posEndPageSetup == posEndEps && implicitPageSetup && !inRemovableEmbedding && !line.empty() &&
line.front() != '%') {
posEndPageSetup = startPos;
#ifdef DEBUG
EXV_DEBUG << "readWriteEpsMetadata: Found implicit EndPageSetup at position: " << startPos << "\n";
#endif
}
if (!line.empty() && line[0] != '%')
if (!line.empty() && line.front() != '%')
continue; // performance optimization
if (line == "%%EOF" || line == "%%Trailer" || line == "%%PageTrailer") {
if (posBeginPageSetup == posEndEps) {
Expand Down
2 changes: 1 addition & 1 deletion src/makernote_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const TiffMnRegistry TiffMnCreator::registry_[] = {

bool TiffMnRegistry::operator==(const std::string& key) const {
std::string make(make_);
if (!key.empty() && key[0] == '-')
if (!key.empty() && key.front() == '-')
return false;
return make == key.substr(0, make.length());
}
Expand Down
2 changes: 1 addition & 1 deletion src/pngchunk_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ std::string PngChunk::writeRawProfile(const std::string& profileData, const char

std::ostringstream oss;
oss << '\n' << profileType << '\n' << std::setw(8) << profileData.size();
const byte* sp = reinterpret_cast<const byte*>(profileData.data());
auto sp = reinterpret_cast<const byte*>(profileData.data());
for (std::string::size_type i = 0; i < profileData.size(); ++i) {
if (i % 36 == 0)
oss << '\n';
Expand Down
14 changes: 7 additions & 7 deletions src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4868,7 +4868,7 @@ std::mutex XmpProperties::mutex_;

/// \todo not used internally. At least we should test it
const XmpNsInfo* XmpProperties::lookupNsRegistry(const XmpNsInfo::Prefix& prefix) {
std::lock_guard<std::mutex> scoped_read_lock(mutex_);
auto scoped_read_lock = std::scoped_lock(mutex_);
return lookupNsRegistryUnsafe(prefix);
}

Expand All @@ -4881,7 +4881,7 @@ const XmpNsInfo* XmpProperties::lookupNsRegistryUnsafe(const XmpNsInfo::Prefix&
}

void XmpProperties::registerNs(const std::string& ns, const std::string& prefix) {
std::lock_guard<std::mutex> scoped_write_lock(mutex_);
auto scoped_write_lock = std::scoped_lock(mutex_);
std::string ns2 = ns;
if (ns2.substr(ns2.size() - 1, 1) != "/" && ns2.substr(ns2.size() - 1, 1) != "#")
ns2 += "/";
Expand Down Expand Up @@ -4911,7 +4911,7 @@ void XmpProperties::registerNs(const std::string& ns, const std::string& prefix)
}

void XmpProperties::unregisterNs(const std::string& ns) {
std::lock_guard<std::mutex> scoped_write_lock(mutex_);
auto scoped_write_lock = std::scoped_lock(mutex_);
unregisterNsUnsafe(ns);
}

Expand All @@ -4925,7 +4925,7 @@ void XmpProperties::unregisterNsUnsafe(const std::string& ns) {
}

void XmpProperties::unregisterNs() {
std::lock_guard<std::mutex> scoped_write_lock(mutex_);
auto scoped_write_lock = std::scoped_lock(mutex_);
/// \todo check if we are not unregistering the first NS
auto i = nsRegistry_.begin();
while (i != nsRegistry_.end()) {
Expand All @@ -4935,7 +4935,7 @@ void XmpProperties::unregisterNs() {
}

std::string XmpProperties::prefix(const std::string& ns) {
std::lock_guard<std::mutex> scoped_read_lock(mutex_);
auto scoped_read_lock = std::scoped_lock(mutex_);
std::string ns2 = ns;
if (ns2.substr(ns2.size() - 1, 1) != "/" && ns2.substr(ns2.size() - 1, 1) != "#")
ns2 += "/";
Expand All @@ -4953,7 +4953,7 @@ std::string XmpProperties::prefix(const std::string& ns) {
}

std::string XmpProperties::ns(const std::string& prefix) {
std::lock_guard<std::mutex> scoped_read_lock(mutex_);
auto scoped_read_lock = std::scoped_lock(mutex_);
const XmpNsInfo* xn = lookupNsRegistryUnsafe(XmpNsInfo::Prefix(prefix));
if (xn)
return xn->ns_;
Expand Down Expand Up @@ -5016,7 +5016,7 @@ const XmpPropertyInfo* XmpProperties::propertyList(const std::string& prefix) {
}

const XmpNsInfo* XmpProperties::nsInfo(const std::string& prefix) {
std::lock_guard<std::mutex> scoped_read_lock(mutex_);
auto scoped_read_lock = std::scoped_lock(mutex_);
return nsInfoUnsafe(prefix);
}

Expand Down
4 changes: 2 additions & 2 deletions src/tags_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ std::ostream& printVersion(std::ostream& os, const std::string& str) {
if (str.size() != 4) {
return os << "(" << str << ")";
}
if (str[0] != '0')
os << str[0];
if (str.front() != '0')
os << str.front();
return os << str[1] << "." << str[2] << str[3];
}
} // namespace
Expand Down
2 changes: 1 addition & 1 deletion src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ void TiffReader::readTiffEntry(TiffEntryBase* object) {
v->read(pData, size, byteOrder());

object->setValue(std::move(v));
object->setData(pData, size, std::shared_ptr<DataBuf>());
object->setData(pData, size, std::make_shared<DataBuf>());
object->setOffset(offset);
object->setIdx(nextIdx(object->group()));

Expand Down
6 changes: 3 additions & 3 deletions src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ int CommentValue::read(const std::string& comment) {
const std::string::size_type pos = comment.find_first_of(' ');
std::string name = comment.substr(8, pos - 8);
// Strip quotes (so you can also specify the charset without quotes)
if (!name.empty() && name[0] == '"')
if (!name.empty() && name.front() == '"')
name = name.substr(1);
if (!name.empty() && name[name.length() - 1] == '"')
name = name.substr(0, name.length() - 1);
Expand Down Expand Up @@ -499,7 +499,7 @@ int XmpTextValue::read(const std::string& buf) {
std::string::size_type pos = buf.find_first_of(' ');
type = buf.substr(5, pos - 5);
// Strip quotes (so you can also specify the type without quotes)
if (!type.empty() && type[0] == '"')
if (!type.empty() && type.front() == '"')
type = type.substr(1);
if (!type.empty() && type[type.length() - 1] == '"')
type = type.substr(0, type.length() - 1);
Expand Down Expand Up @@ -662,7 +662,7 @@ int LangAltValue::read(const std::string& buf) {
if (lang.empty())
throw Error(ErrorCode::kerInvalidLangAltValue, buf);
// Strip quotes (so you can also specify the language without quotes)
if (lang[0] == '"') {
if (lang.front() == '"') {
lang = lang.substr(1);

if (lang.empty() || lang.find('"') != lang.length() - 1)
Expand Down
9 changes: 3 additions & 6 deletions src/xmpsidecar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,9 @@ bool isXmpType(BasicIo& iIo, bool advance) {
std::string head(reinterpret_cast<const char*>(buf + start), len - start);
if (head.substr(0, 5) == "<?xml") {
// Forward to the next tag
for (size_t i = 5; i < head.size(); ++i) {
if (head[i] == '<') {
head = head.substr(i);
break;
}
}
auto it = std::find(head.begin() + 5, head.end(), '<');
if (it != head.end())
head = head.substr(std::distance(head.begin(), it));
}
if (head.size() > 9 && (head.substr(0, 9) == "<?xpacket" || head.substr(0, 10) == "<x:xmpmeta")) {
rc = true;
Expand Down