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

cppcheck fixes #2478

Merged
merged 5 commits into from
Jan 27, 2023
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: 2 additions & 2 deletions app/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ int Rename::run(const std::string& path) {
return 1;
}
std::string v = md->toString();
if (v.length() == 0 || v[0] == ' ') {
if (v.empty() || v.front() == ' ') {
std::cerr << _("Image file creation timestamp not set in the file") << " " << path << "\n";
return 1;
}
Expand Down Expand Up @@ -1602,7 +1602,7 @@ int Timestamp::touch(const std::string& path) const {
//! @endcond

int str2Tm(const std::string& timeStr, struct tm* tm) {
if (timeStr.length() == 0 || timeStr[0] == ' ')
if (timeStr.empty() || timeStr.front() == ' ')
return 1;
if (timeStr.length() < 19)
return 2;
Expand Down
6 changes: 3 additions & 3 deletions include/exiv2/asfvideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class EXIV2API AsfVideo : public Image {
explicit AsfVideo(BasicIo::UniquePtr io);

//! Copy constructor
AsfVideo(const AsfVideo& rhs) = delete;
AsfVideo(const AsfVideo&) = delete;
//! Assignment operator
AsfVideo& operator=(const AsfVideo& rhs) = delete;
AsfVideo& operator=(const AsfVideo&) = delete;
//@}

//! @name Manipulators
Expand Down Expand Up @@ -170,4 +170,4 @@ EXIV2API bool isAsfType(BasicIo& iIo, bool advance);

} // namespace Exiv2

#endif // #ifndef ASFVIDEO_HPP_
#endif // #ifndef ASFVIDEO_HPP_
4 changes: 2 additions & 2 deletions include/exiv2/riffvideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class EXIV2API RiffVideo : public Image {
explicit RiffVideo(BasicIo::UniquePtr io);

//! Copy constructor
RiffVideo(const RiffVideo& rhs) = delete;
RiffVideo(const RiffVideo&) = delete;
//! Assignment operator
RiffVideo& operator=(const RiffVideo& rhs) = delete;
RiffVideo& operator=(const RiffVideo&) = delete;

//@}

Expand Down
4 changes: 2 additions & 2 deletions src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ void Converter::cnvExifDate(const char* from, const char* to) {
}

if (subsec.size() > 10)
subsec = subsec.substr(0, 10);
subsec.resize(10);
snprintf(buf, sizeof(buf), "%4d-%02d-%02dT%02d:%02d:%02d%s", year, month, day, hour, min, sec, subsec.c_str());
buf[sizeof(buf) - 1] = 0;

Expand Down Expand Up @@ -1141,7 +1141,7 @@ void Converter::cnvXmpGPSCoord(const char* from, const char* to) {
double deg = 0.0;
double min = 0.0;
double sec = 0.0;
char ref = value[value.length() - 1];
char ref = value.back();
char sep1 = '\0';
char sep2 = '\0';

Expand Down
2 changes: 1 addition & 1 deletion src/futils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ size_t base64decode(const char* in, char* out, size_t out_size) {

Protocol fileProtocol(const std::string& path) {
Protocol result = pFile;
struct {
const struct {
std::string name;
Protocol prot;
bool isUrl; // path.size() > name.size()
Expand Down
12 changes: 6 additions & 6 deletions src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ static int makeNonBlocking(int sockfd) {
}

int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::string& errors) {
if (!request.count("verb"))
if (request.find("verb") == request.end())
request["verb"] = "GET";
if (!request.count("header"))
if (request.find("header") == request.end())
request["header"] = "";
if (!request.count("version"))
if (request.find("version") == request.end())
request["version"] = "1.0";
if (!request.count("port"))
if (request.find("port") == request.end())
request["port"] = "";

std::string file;
Expand Down Expand Up @@ -305,8 +305,8 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
while (c && first_newline && c < first_newline && h < buffer + body) {
std::string key(h);
std::string value(c + 1);
key = key.substr(0, c - h);
value = value.substr(0, first_newline - c - 1);
key.resize(c - h);
value.resize(first_newline - c - 1);
response[key] = value;
h = first_newline + 1;
c = strchr(h, C);
Expand Down
4 changes: 2 additions & 2 deletions src/olympusmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ std::ostream& OlympusMakerNote::print0x0201(std::ostream& os, const Value& value

// 6 numbers: 0. Make, 1. Unknown, 2. Model, 3. Sub-model, 4-5. Unknown.
// Only the Make, Model and Sub-model are used to determine the lens model
static struct {
static const struct {
byte val[3];
const char* label;
} lensTypes[] = {
Expand Down Expand Up @@ -1397,7 +1397,7 @@ std::ostream& OlympusMakerNote::print0x0209(std::ostream& os, const Value& value
std::ostream& OlympusMakerNote::printEq0x0301(std::ostream& os, const Value& value, const ExifData*) {
// 6 numbers: 0. Make, 1. Unknown, 2. Model, 3. Sub-model, 4-5. Unknown.
// Only the Make and Model are used to determine the extender model
static struct {
static const struct {
byte val[2];
const char* label;
} extenderModels[] = {
Expand Down
2 changes: 1 addition & 1 deletion src/pngimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, si
}
while (dataString.size() < iMax)
dataString += ' ';
dataString = dataString.substr(0, iMax);
dataString.resize(iMax);

if (bPrint) {
io_->seek(dataOffset, BasicIo::cur); // jump to checksum
Expand Down
8 changes: 4 additions & 4 deletions src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4942,8 +4942,8 @@ const XmpNsInfo* XmpProperties::lookupNsRegistryUnsafe(const XmpNsInfo::Prefix&
void XmpProperties::registerNs(const std::string& ns, const std::string& prefix) {
auto scopedWriteLock = std::scoped_lock(mutex_);
std::string ns2 = ns;
if (ns2.substr(ns2.size() - 1, 1) != "/" && ns2.substr(ns2.size() - 1, 1) != "#")
ns2 += "/";
if (ns2.back() != '/' && ns2.back() != '#')
ns2 += '/';
// Check if there is already a registered namespace with this prefix
const XmpNsInfo* xnp = lookupNsRegistryUnsafe(XmpNsInfo::Prefix(prefix));
if (xnp) {
Expand Down Expand Up @@ -4995,8 +4995,8 @@ void XmpProperties::unregisterNs() {
std::string XmpProperties::prefix(const std::string& ns) {
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 += "/";
if (ns2.back() != '/' && ns2.back() != '#')
ns2 += '/';

auto i = nsRegistry_.find(ns2);
std::string p;
Expand Down
2 changes: 1 addition & 1 deletion src/sonymn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,7 @@ std::ostream& SonyMakerNote::printSony2FpFocusPosition2(std::ostream& os, const
}

// Ranges of models that do not support this tag
for (auto& m : {"DSC-", "Stellar"}) {
for (const auto& m : {"DSC-", "Stellar"}) {
if (startsWith(model, m)) {
os << N_("n/a");
return os;
Expand Down
19 changes: 0 additions & 19 deletions src/tiffcomposite_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,6 @@ TiffEntryBase::TiffEntryBase(const TiffEntryBase& rhs) :
storage_(rhs.storage_) {
}

TiffDirectory::TiffDirectory(const TiffDirectory& rhs) : TiffComponent(rhs), hasNext_(rhs.hasNext_) {
}

TiffSubIfd::TiffSubIfd(const TiffSubIfd& rhs) : TiffEntryBase(rhs), newGroup_(rhs.newGroup_) {
}

TiffBinaryArray::TiffBinaryArray(const TiffBinaryArray& rhs) :
TiffEntryBase(rhs),
cfgSelFct_(rhs.cfgSelFct_),
arraySet_(rhs.arraySet_),
arrayCfg_(rhs.arrayCfg_),
arrayDef_(rhs.arrayDef_),
defSize_(rhs.defSize_),
setSize_(rhs.setSize_),
origData_(rhs.origData_),
origSize_(rhs.origSize_),
pRoot_(rhs.pRoot_) {
}

TiffComponent::UniquePtr TiffComponent::clone() const {
return UniquePtr(doClone());
}
Expand Down
6 changes: 3 additions & 3 deletions src/tiffcomposite_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ class TiffDirectory : public TiffComponent {
//! @name Protected Creators
//@{
//! Copy constructor (used to implement clone()).
TiffDirectory(const TiffDirectory& rhs);
TiffDirectory(const TiffDirectory&) = default;
//@}

//! @name Protected Manipulators
Expand Down Expand Up @@ -958,7 +958,7 @@ class TiffSubIfd : public TiffEntryBase {
//! @name Protected Creators
//@{
//! Copy constructor (used to implement clone()).
TiffSubIfd(const TiffSubIfd& rhs);
TiffSubIfd(const TiffSubIfd&) = default;
TiffSubIfd& operator=(const TiffSubIfd&) = delete;
//@}

Expand Down Expand Up @@ -1360,7 +1360,7 @@ class TiffBinaryArray : public TiffEntryBase {
//! @name Protected Creators
//@{
//! Copy constructor (used to implement clone()).
TiffBinaryArray(const TiffBinaryArray& rhs);
TiffBinaryArray(const TiffBinaryArray&) = default;
//@}

//! @name Protected Manipulators
Expand Down
14 changes: 7 additions & 7 deletions src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ AsciiValue::AsciiValue(const std::string& buf) : StringValueBase(asciiString, bu
int AsciiValue::read(const std::string& buf) {
value_ = buf;
// ensure count>0 and nul terminated # https://github.com/Exiv2/exiv2/issues/1484
if (value_.empty() || value_.at(value_.size() - 1) != '\0') {
if (value_.empty() || value_.back() != '\0') {
value_ += '\0';
}
return 0;
Expand Down Expand Up @@ -325,8 +325,8 @@ int CommentValue::read(const std::string& comment) {
// Strip quotes (so you can also specify the charset without quotes)
if (!name.empty() && name.front() == '"')
name = name.substr(1);
if (!name.empty() && name[name.length() - 1] == '"')
name = name.substr(0, name.length() - 1);
if (!name.empty() && name.back() == '"')
name.pop_back();
charsetId = CharsetInfo::charsetIdByName(name);
if (charsetId == invalidCharsetId) {
#ifndef SUPPRESS_WARNINGS
Expand Down Expand Up @@ -391,7 +391,7 @@ std::string CommentValue::comment(const char* encoding) const {
bool bAscii = charsetId() == undefined || charsetId() == ascii;
// # 1266 Remove trailing nulls
if (bAscii && c.find('\0') != std::string::npos) {
c = c.substr(0, c.find('\0'));
c.resize(c.find('\0'));
}
return c;
}
Expand Down Expand Up @@ -503,8 +503,8 @@ int XmpTextValue::read(const std::string& buf) {
// Strip quotes (so you can also specify the type without quotes)
if (!type.empty() && type.front() == '"')
type = type.substr(1);
if (!type.empty() && type[type.length() - 1] == '"')
type = type.substr(0, type.length() - 1);
if (!type.empty() && type.back() == '"')
type.pop_back();
b.clear();
if (pos != std::string::npos)
b = buf.substr(pos + 1);
Expand Down Expand Up @@ -670,7 +670,7 @@ int LangAltValue::read(const std::string& buf) {
if (lang.empty() || lang.find('"') != lang.length() - 1)
throw Error(ErrorCode::kerInvalidLangAltValue, buf);

lang = lang.substr(0, lang.length() - 1);
lang.pop_back();
}

if (lang.empty())
Expand Down
9 changes: 3 additions & 6 deletions src/xmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,8 @@ static XMP_Status nsDumper(void* refCon, XMP_StringPtr buffer, XMP_StringLen buf
bool bNS = out.find(':') != std::string::npos && !bURI;

// pop trailing ':' on a namespace
if (bNS && !out.empty()) {
std::size_t length = out.length();
if (out[length - 1] == ':')
out = out.substr(0, length - 1);
}
if (bNS && !out.empty() && out.back() == ':')
out.pop_back();

if (bURI || bNS) {
auto p = static_cast<std::map<std::string, std::string>*>(refCon);
Expand Down Expand Up @@ -706,7 +703,7 @@ int XmpParser::decode(XmpData& xmpData, const std::string& xmpPacket) {
bool ret = SXMPMeta::GetNamespacePrefix(schemaNs.c_str(), &prefix);
if (!ret)
throw Error(ErrorCode::kerSchemaNamespaceNotRegistered, schemaNs);
prefix = prefix.substr(0, prefix.size() - 1);
prefix.pop_back();
XmpProperties::registerNs(schemaNs, prefix);
}
continue;
Expand Down