mirror of
https://github.com/taglib/taglib.git
synced 2026-02-14 12:13:07 -05: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:
@ -53,7 +53,6 @@ public:
|
||||
pages.setAutoDelete(true);
|
||||
}
|
||||
|
||||
unsigned int streamSerialNumber;
|
||||
List<Page *> pages;
|
||||
std::unique_ptr<PageHeader> firstPageHeader;
|
||||
std::unique_ptr<PageHeader> lastPageHeader;
|
||||
@ -148,8 +147,8 @@ bool Ogg::File::save()
|
||||
return false;
|
||||
}
|
||||
|
||||
for(const auto &[i, packet] : std::as_const(d->dirtyPackets))
|
||||
writePacket(i, packet);
|
||||
for(const auto &[i, pkt] : std::as_const(d->dirtyPackets))
|
||||
writePacket(i, pkt);
|
||||
|
||||
d->dirtyPackets.clear();
|
||||
|
||||
@ -282,10 +281,10 @@ void Ogg::File::writePacket(unsigned int i, const ByteVector &packet)
|
||||
break;
|
||||
|
||||
page.setPageSequenceNumber(page.pageSequenceNumber() + numberOfNewPages);
|
||||
const ByteVector data = page.render();
|
||||
const ByteVector pageData = page.render();
|
||||
|
||||
seek(pageOffset + 18);
|
||||
writeBlock(data.mid(18, 8));
|
||||
writeBlock(pageData.mid(18, 8));
|
||||
|
||||
if(page.header()->lastPageOfStream())
|
||||
break;
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#include "oggpage.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <array>
|
||||
#include <utility>
|
||||
|
||||
@ -91,10 +92,10 @@ unsigned int pageChecksum(const ByteVector &data)
|
||||
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
|
||||
};
|
||||
|
||||
unsigned int sum = 0;
|
||||
for(const auto &byte : data)
|
||||
sum = (sum << 8) ^ crcTable[((sum >> 24) & 0xff) ^ static_cast<unsigned char>(byte)];
|
||||
return sum;
|
||||
return std::accumulate(data.cbegin(), data.cend(), 0U,
|
||||
[](unsigned int sum, unsigned char byte) {
|
||||
return (sum << 8) ^ crcTable[((sum >> 24) & 0xff) ^ byte];
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -212,8 +213,8 @@ ByteVectorList Ogg::Page::packets() const
|
||||
d->file->seek(d->fileOffset + d->header.size());
|
||||
|
||||
const List<int> packetSizes = d->header.packetSizes();
|
||||
for(const auto &size : packetSizes)
|
||||
l.append(d->file->readBlock(size));
|
||||
for(const auto &sz : packetSizes)
|
||||
l.append(d->file->readBlock(sz));
|
||||
}
|
||||
else
|
||||
debug("Ogg::Page::packets() -- attempting to read packets from an invalid page.");
|
||||
@ -272,9 +273,10 @@ List<Ogg::Page *> Ogg::Page::paginate(const ByteVectorList &packets,
|
||||
|
||||
if(strategy != Repaginate) {
|
||||
|
||||
size_t tableSize = 0;
|
||||
for(const auto &packet : packets)
|
||||
tableSize += packet.size() / 255 + 1;
|
||||
size_t tableSize = std::accumulate(packets.cbegin(), packets.cend(), 0,
|
||||
[](size_t acc, const ByteVector &packet) {
|
||||
return acc + packet.size() / 255 + 1;
|
||||
});
|
||||
|
||||
if(tableSize > 255)
|
||||
strategy = Repaginate;
|
||||
|
||||
@ -65,34 +65,34 @@ Ogg::XiphComment::~XiphComment() = default;
|
||||
|
||||
String Ogg::XiphComment::title() const
|
||||
{
|
||||
StringList value = d->fieldListMap.value("TITLE");
|
||||
return value.isEmpty() ? String() : joinTagValues(value);
|
||||
StringList val = d->fieldListMap.value("TITLE");
|
||||
return val.isEmpty() ? String() : joinTagValues(val);
|
||||
}
|
||||
|
||||
String Ogg::XiphComment::artist() const
|
||||
{
|
||||
StringList value = d->fieldListMap.value("ARTIST");
|
||||
return value.isEmpty() ? String() : joinTagValues(value);
|
||||
StringList val = d->fieldListMap.value("ARTIST");
|
||||
return val.isEmpty() ? String() : joinTagValues(val);
|
||||
}
|
||||
|
||||
String Ogg::XiphComment::album() const
|
||||
{
|
||||
StringList value = d->fieldListMap.value("ALBUM");
|
||||
return value.isEmpty() ? String() : joinTagValues(value);
|
||||
StringList val = d->fieldListMap.value("ALBUM");
|
||||
return val.isEmpty() ? String() : joinTagValues(val);
|
||||
}
|
||||
|
||||
String Ogg::XiphComment::comment() const
|
||||
{
|
||||
StringList value = d->fieldListMap.value("DESCRIPTION");
|
||||
if(!value.isEmpty()) {
|
||||
StringList val = d->fieldListMap.value("DESCRIPTION");
|
||||
if(!val.isEmpty()) {
|
||||
d->commentField = "DESCRIPTION";
|
||||
return joinTagValues(value);
|
||||
return joinTagValues(val);
|
||||
}
|
||||
|
||||
value = d->fieldListMap.value("COMMENT");
|
||||
if(!value.isEmpty()) {
|
||||
val = d->fieldListMap.value("COMMENT");
|
||||
if(!val.isEmpty()) {
|
||||
d->commentField = "COMMENT";
|
||||
return joinTagValues(value);
|
||||
return joinTagValues(val);
|
||||
}
|
||||
|
||||
return String();
|
||||
@ -100,29 +100,29 @@ String Ogg::XiphComment::comment() const
|
||||
|
||||
String Ogg::XiphComment::genre() const
|
||||
{
|
||||
StringList value = d->fieldListMap.value("GENRE");
|
||||
return value.isEmpty() ? String() : joinTagValues(value);
|
||||
StringList val = d->fieldListMap.value("GENRE");
|
||||
return val.isEmpty() ? String() : joinTagValues(val);
|
||||
}
|
||||
|
||||
unsigned int Ogg::XiphComment::year() const
|
||||
{
|
||||
StringList value = d->fieldListMap.value("DATE");
|
||||
if(!value.isEmpty())
|
||||
return value.front().toInt();
|
||||
value = d->fieldListMap.value("YEAR");
|
||||
if(!value.isEmpty())
|
||||
return value.front().toInt();
|
||||
StringList val = d->fieldListMap.value("DATE");
|
||||
if(!val.isEmpty())
|
||||
return val.front().toInt();
|
||||
val = d->fieldListMap.value("YEAR");
|
||||
if(!val.isEmpty())
|
||||
return val.front().toInt();
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int Ogg::XiphComment::track() const
|
||||
{
|
||||
StringList value = d->fieldListMap.value("TRACKNUMBER");
|
||||
if(!value.isEmpty())
|
||||
return value.front().toInt();
|
||||
value = d->fieldListMap.value("TRACKNUM");
|
||||
if(!value.isEmpty())
|
||||
return value.front().toInt();
|
||||
StringList val = d->fieldListMap.value("TRACKNUMBER");
|
||||
if(!val.isEmpty())
|
||||
return val.front().toInt();
|
||||
val = d->fieldListMap.value("TRACKNUM");
|
||||
if(!val.isEmpty())
|
||||
return val.front().toInt();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -246,7 +246,7 @@ StringList Ogg::XiphComment::complexPropertyKeys() const
|
||||
|
||||
List<VariantMap> Ogg::XiphComment::complexProperties(const String &key) const
|
||||
{
|
||||
List<VariantMap> properties;
|
||||
List<VariantMap> props;
|
||||
const String uppercaseKey = key.upper();
|
||||
if(uppercaseKey == "PICTURE") {
|
||||
for(const FLAC::Picture *picture : std::as_const(d->pictureList)) {
|
||||
@ -260,10 +260,10 @@ List<VariantMap> Ogg::XiphComment::complexProperties(const String &key) const
|
||||
property.insert("height", picture->height());
|
||||
property.insert("numColors", picture->numColors());
|
||||
property.insert("colorDepth", picture->colorDepth());
|
||||
properties.append(property);
|
||||
props.append(property);
|
||||
}
|
||||
}
|
||||
return properties;
|
||||
return props;
|
||||
}
|
||||
|
||||
bool Ogg::XiphComment::setComplexProperties(const String &key, const List<VariantMap> &value)
|
||||
@ -398,10 +398,10 @@ ByteVector Ogg::XiphComment::render(bool addFramingBit) const
|
||||
|
||||
for(const auto &[fieldName, values] : std::as_const(d->fieldListMap)) {
|
||||
// And now iterate over the values of the current list.
|
||||
for(const auto &value : values) {
|
||||
for(const auto &val : values) {
|
||||
ByteVector fieldData = fieldName.data(String::UTF8);
|
||||
fieldData.append('=');
|
||||
fieldData.append(value.data(String::UTF8));
|
||||
fieldData.append(val.data(String::UTF8));
|
||||
|
||||
data.append(ByteVector::fromUInt(fieldData.size(), false));
|
||||
data.append(fieldData);
|
||||
|
||||
Reference in New Issue
Block a user