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:
Urs Fleisch
2023-12-03 11:59:24 +01:00
parent 131918333b
commit 8b3f1a459e
38 changed files with 349 additions and 354 deletions

View File

@@ -272,8 +272,8 @@ int ID3v1::genreIndex(const String &name)
std::pair(L"BritPop", 132),
std::pair(L"Negerpunk", 133),
};
for(const auto &[genre, code] : fixUpGenres) {
if(name == genre)
for(const auto &[genreName, code] : fixUpGenres) {
if(name == genreName)
return code;
}

View File

@@ -340,13 +340,15 @@ PropertyMap TextIdentificationFrame::makeTMCLProperties() const
const StringList l = fieldList();
for(auto it = l.begin(); it != l.end(); ++it) {
String instrument = it->upper();
if(instrument.isEmpty()) {
// ++it == l.end() is not possible with size check above,
// verified to silence cppcheck.
if(instrument.isEmpty() || ++it == l.end()) {
// instrument is not a valid key -> frame unsupported
map.clear();
map.addUnsupportedData(frameID());
return map;
}
map.insert(L"PERFORMER:" + instrument, (++it)->split(","));
map.insert(L"PERFORMER:" + instrument, it->split(","));
}
return map;
}

View File

@@ -131,7 +131,7 @@ std::pair<Frame::Header *, bool> FrameFactory::prepareFrameHeader(
}
#ifndef NO_ITUNES_HACKS
if(version == 3 && frameID.size() == 4 && frameID[3] == '\0') {
if(version == 3 && frameID[3] == '\0') {
// iTunes v2.3 tags store v2.2 frames - convert now
frameID = frameID.mid(0, 3);
header->setFrameID(frameID);

View File

@@ -25,6 +25,7 @@
#include "id3v2header.h"
#include <algorithm>
#include <bitset>
#include "tstring.h"
@@ -197,12 +198,11 @@ void Header::parse(const ByteVector &data)
return;
}
for(const auto &size : sizeData) {
if(static_cast<unsigned char>(size) >= 128) {
d->tagSize = 0;
debug("TagLib::ID3v2::Header::parse() - One of the size bytes in the id3v2 header was greater than the allowed 128.");
return;
}
if(std::any_of(sizeData.cbegin(), sizeData.cend(),
[](unsigned char size) { return size >= 128; })) {
d->tagSize = 0;
debug("TagLib::ID3v2::Header::parse() - One of the size bytes in the id3v2 header was greater than the allowed 128.");
return;
}
// The first three bytes, data[0..2], are the File Identifier, "ID3". (structure 3.1 "file identifier")

View File

@@ -146,10 +146,10 @@ String ID3v2::Tag::comment() const
if(comments.isEmpty())
return String();
for(const auto &comment : comments) {
auto frame = dynamic_cast<CommentsFrame *>(comment);
for(const auto &commFrame : comments) {
auto frame = dynamic_cast<CommentsFrame *>(commFrame);
if(frame && frame->description().isEmpty())
return comment->toString();
return commFrame->toString();
}
return comments.front()->toString();
@@ -234,10 +234,10 @@ void ID3v2::Tag::setComment(const String &s)
const FrameList &comments = d->frameListMap["COMM"];
if(!comments.isEmpty()) {
for(const auto &comment : comments) {
auto frame = dynamic_cast<CommentsFrame *>(comment);
for(const auto &commFrame : comments) {
auto frame = dynamic_cast<CommentsFrame *>(commFrame);
if(frame && frame->description().isEmpty()) {
comment->setText(s);
commFrame->setText(s);
return;
}
}
@@ -408,10 +408,10 @@ PropertyMap ID3v2::Tag::setProperties(const PropertyMap &origProps)
FrameList framesToDelete;
// we split up the PropertyMap into the "normal" keys and the "complicated" ones,
// which are those according to TIPL or TMCL frames.
PropertyMap properties;
PropertyMap singleFrameProperties;
PropertyMap tiplProperties;
PropertyMap tmclProperties;
Frame::splitProperties(origProps, properties, tiplProperties, tmclProperties);
Frame::splitProperties(origProps, singleFrameProperties, tiplProperties, tmclProperties);
for(const auto &[tag, frames] : std::as_const(frameListMap())) {
for(const auto &frame : frames) {
PropertyMap frameProperties = frame->asProperties();
@@ -427,10 +427,10 @@ PropertyMap ID3v2::Tag::setProperties(const PropertyMap &origProps)
else
tmclProperties.erase(frameProperties);
}
else if(!properties.contains(frameProperties))
else if(!singleFrameProperties.contains(frameProperties))
framesToDelete.append(frame);
else
properties.erase(frameProperties);
singleFrameProperties.erase(frameProperties);
}
}
for(const auto &frame : std::as_const(framesToDelete))
@@ -444,7 +444,7 @@ PropertyMap ID3v2::Tag::setProperties(const PropertyMap &origProps)
if(!tmclProperties.isEmpty())
addFrame(TextIdentificationFrame::createTMCLFrame(tmclProperties));
// now create the "one key per frame" frames
for(const auto &[tag, frames] : std::as_const(properties))
for(const auto &[tag, frames] : std::as_const(singleFrameProperties))
addFrame(d->factory->createFrameForProperty(tag, frames));
return PropertyMap(); // ID3 implements the complete PropertyMap interface, so an empty map is returned
}
@@ -463,7 +463,7 @@ StringList ID3v2::Tag::complexPropertyKeys() const
List<VariantMap> ID3v2::Tag::complexProperties(const String &key) const
{
List<VariantMap> properties;
List<VariantMap> props;
const String uppercaseKey = key.upper();
if(uppercaseKey == "PICTURE") {
const FrameList pictures = d->frameListMap.value("APIC");
@@ -475,7 +475,7 @@ List<VariantMap> ID3v2::Tag::complexProperties(const String &key) const
property.insert("description", picture->description());
property.insert("pictureType",
AttachedPictureFrame::typeToString(picture->type()));
properties.append(property);
props.append(property);
}
}
}
@@ -488,11 +488,11 @@ List<VariantMap> ID3v2::Tag::complexProperties(const String &key) const
property.insert("mimeType", geob->mimeType());
property.insert("description", geob->description());
property.insert("fileName", geob->fileName());
properties.append(property);
props.append(property);
}
}
}
return properties;
return props;
}
bool ID3v2::Tag::setComplexProperties(const String &key, const List<VariantMap> &value)
@@ -679,12 +679,12 @@ ByteVector ID3v2::Tag::render(Version version) const
FrameList newFrames;
newFrames.setAutoDelete(true);
FrameList frameList;
FrameList frames;
if(version == v4) {
frameList = d->frameList;
frames = d->frameList;
}
else {
downgradeFrames(&frameList, &newFrames);
downgradeFrames(&frames, &newFrames);
}
// Reserve a 10-byte blank space for an ID3v2 tag header.
@@ -693,7 +693,7 @@ ByteVector ID3v2::Tag::render(Version version) const
// Loop through the frames rendering them and adding them to the tagData.
for(const auto &frame : std::as_const(frameList)) {
for(const auto &frame : std::as_const(frames)) {
frame->header()->setVersion(version == v3 ? 3 : 4);
if(frame->header()->frameID().size() != 4) {
debug("An ID3v2 frame of unsupported or unknown type \'"

View File

@@ -308,14 +308,16 @@ void MPEG::Header::parse(File *file, offset_t offset, bool checkLength)
// Samples per frame
static constexpr std::array samplesPerFrame {
static constexpr std::array samplesPerFrameForLayer {
// MPEG1, 2/2.5
std::pair(384, 384), // Layer I
std::pair(1152, 1152), // Layer II
std::pair(1152, 576), // Layer III
};
d->samplesPerFrame = versionIndex ? samplesPerFrame[layerIndex].second : samplesPerFrame[layerIndex].first;
d->samplesPerFrame = versionIndex
? samplesPerFrameForLayer[layerIndex].second
: samplesPerFrameForLayer[layerIndex].first;
// Calculate the frame length

View File

@@ -165,7 +165,7 @@ void MPEG::Properties::read(File *file, ReadStyle readStyle)
d->bitrate = static_cast<int>(d->xingHeader->totalSize() * 8.0 / length + 0.5);
}
else {
int bitrate = firstHeader.bitrate();
int bitRate = firstHeader.bitrate();
if(firstHeader.isADTS()) {
// ADTS is probably VBR, so to get the real length, we would have to go
// through all frames, count the frames in numFrames and sum their
@@ -180,7 +180,7 @@ void MPEG::Properties::read(File *file, ReadStyle readStyle)
// for 10 frames and then calculate the length from the estimated bitrate
// and the stream length.
if(readStyle == Fast) {
bitrate = 0;
bitRate = 0;
d->length = 0;
}
else {
@@ -210,7 +210,7 @@ void MPEG::Properties::read(File *file, ReadStyle readStyle)
lastBytesPerFrame = bytesPerFrame;
}
}
bitrate = firstHeader.samplesPerFrame() != 0
bitRate = firstHeader.samplesPerFrame() != 0
? static_cast<int>((bytesPerFrame * 8 * firstHeader.sampleRate())
/ 1000 / firstHeader.samplesPerFrame())
: 0;
@@ -222,10 +222,10 @@ void MPEG::Properties::read(File *file, ReadStyle readStyle)
// TODO: Make this more robust with audio property detection for VBR without a
// Xing header.
bitrate = firstHeader.bitrate();
bitRate = firstHeader.bitrate();
}
if(bitrate > 0) {
d->bitrate = bitrate;
if(bitRate > 0) {
d->bitrate = bitRate;
// Look for the last MPEG audio frame to calculate the stream length.