mirror of
https://github.com/taglib/taglib.git
synced 2026-07-13 14:51:05 -04:00
Fix issues reported by CppCheck
Many shadowFunction, some useStlAlgorithm, and others. cppcheck --enable=all --inline-suppr \ --suppress=noExplicitConstructor --suppress=unusedFunction \ --suppress=missingIncludeSystem --project=compile_commands.json
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <numeric>
|
||||
|
||||
#include "tstringlist.h"
|
||||
#include "tdebug.h"
|
||||
@@ -315,20 +316,19 @@ public:
|
||||
|
||||
unsigned int size() const override
|
||||
{
|
||||
unsigned int size = 0;
|
||||
for(const auto &reader : m_readers) {
|
||||
size += reader->size();
|
||||
}
|
||||
return size;
|
||||
return std::accumulate(m_readers.cbegin(), m_readers.cend(), 0U,
|
||||
[](unsigned int acc, const auto &rdr) {
|
||||
return acc + rdr->size();
|
||||
});
|
||||
}
|
||||
|
||||
unsigned int read(TagLib::File &file, unsigned int limit) override
|
||||
{
|
||||
unsigned int sumcount = 0;
|
||||
for(const auto &reader : std::as_const(m_readers)) {
|
||||
for(const auto &rdr : std::as_const(m_readers)) {
|
||||
if(limit == 0)
|
||||
break;
|
||||
unsigned int count = reader->read(file, limit);
|
||||
unsigned int count = rdr->read(file, limit);
|
||||
limit -= count;
|
||||
sumcount += count;
|
||||
}
|
||||
@@ -474,11 +474,11 @@ bool XM::File::save()
|
||||
|
||||
if(sampleHeaderSize > 18U) {
|
||||
seek(pos + 18);
|
||||
const unsigned int len = std::min(sampleHeaderSize - 18U, 22UL);
|
||||
const unsigned int sz = std::min(sampleHeaderSize - 18U, 22UL);
|
||||
if(sampleNameIndex >= lines.size())
|
||||
writeString(String(), len);
|
||||
writeString(String(), sz);
|
||||
else
|
||||
writeString(lines[sampleNameIndex ++], len);
|
||||
writeString(lines[sampleNameIndex ++], sz);
|
||||
}
|
||||
}
|
||||
pos += sampleHeaderSize;
|
||||
@@ -555,11 +555,11 @@ void XM::File::read(bool)
|
||||
StructReader pattern;
|
||||
pattern.byte(packingType).u16L(rowCount).u16L(dataSize);
|
||||
|
||||
unsigned int count = pattern.read(*this, patternHeaderLength - 4U);
|
||||
READ_ASSERT(count == std::min(patternHeaderLength - 4U,
|
||||
unsigned int ptCnt = pattern.read(*this, patternHeaderLength - 4U);
|
||||
READ_ASSERT(ptCnt == std::min(patternHeaderLength - 4U,
|
||||
static_cast<unsigned long>(pattern.size())));
|
||||
|
||||
seek(patternHeaderLength - (4 + count) + dataSize, Current);
|
||||
seek(patternHeaderLength - (4 + ptCnt) + dataSize, Current);
|
||||
}
|
||||
|
||||
StringList instrumentNames;
|
||||
@@ -579,8 +579,8 @@ void XM::File::read(bool)
|
||||
instrument.string(instrumentName, 22).byte(instrumentType).u16L(sampleCount);
|
||||
|
||||
// 4 for instrumentHeaderSize
|
||||
unsigned int count = 4 + instrument.read(*this, instrumentHeaderSize - 4U);
|
||||
READ_ASSERT(count == std::min(instrumentHeaderSize,
|
||||
unsigned int inCnt = 4 + instrument.read(*this, instrumentHeaderSize - 4U);
|
||||
READ_ASSERT(inCnt == std::min(instrumentHeaderSize,
|
||||
static_cast<unsigned long>(instrument.size() + 4)));
|
||||
|
||||
offset_t offset = 0;
|
||||
@@ -588,9 +588,9 @@ void XM::File::read(bool)
|
||||
unsigned long sampleHeaderSize = 0;
|
||||
sumSampleCount += sampleCount;
|
||||
// wouldn't know which header size to assume otherwise:
|
||||
READ_ASSERT(instrumentHeaderSize >= count + 4 && readU32L(sampleHeaderSize));
|
||||
READ_ASSERT(instrumentHeaderSize >= inCnt + 4 && readU32L(sampleHeaderSize));
|
||||
// skip unhandled header proportion:
|
||||
seek(instrumentHeaderSize - count - 4, Current);
|
||||
seek(instrumentHeaderSize - inCnt - 4, Current);
|
||||
|
||||
for(unsigned short j = 0; j < sampleCount; ++ j) {
|
||||
unsigned long sampleLength = 0;
|
||||
@@ -615,18 +615,18 @@ void XM::File::read(bool)
|
||||
.byte(compression)
|
||||
.string(sampleName, 22);
|
||||
|
||||
unsigned int count = sample.read(*this, sampleHeaderSize);
|
||||
READ_ASSERT(count == std::min(sampleHeaderSize,
|
||||
unsigned int smCnt = sample.read(*this, sampleHeaderSize);
|
||||
READ_ASSERT(smCnt == std::min(sampleHeaderSize,
|
||||
static_cast<unsigned long>(sample.size())));
|
||||
// skip unhandled header proportion:
|
||||
seek(sampleHeaderSize - count, Current);
|
||||
seek(sampleHeaderSize - smCnt, Current);
|
||||
|
||||
offset += sampleLength;
|
||||
sampleNames.append(sampleName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
offset = instrumentHeaderSize - count;
|
||||
offset = instrumentHeaderSize - inCnt;
|
||||
}
|
||||
instrumentNames.append(instrumentName);
|
||||
seek(offset, Current);
|
||||
|
||||
Reference in New Issue
Block a user