Skip to content

Commit 39e8957

Browse files
committed
Matroska: Fix issues reported by static analysis, formatting, docs
1 parent cbba03b commit 39e8957

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+622
-675
lines changed

taglib/matroska/ebml/ebmlbinaryelement.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "ebmlbinaryelement.h"
2222
#include "ebmlutils.h"
23+
#include "tfile.h"
2324

2425
using namespace TagLib;
2526

taglib/matroska/ebml/ebmlbinaryelement.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#ifndef DO_NOT_DOCUMENT
2424

2525
#include "ebmlelement.h"
26+
#include "tbytevector.h"
2627

2728
namespace TagLib {
2829
class File;
@@ -31,20 +32,14 @@ namespace TagLib {
3132
{
3233
public:
3334
BinaryElement(Id id, int sizeLength, offset_t dataSize) :
34-
Element(id, sizeLength, dataSize)
35-
{
36-
}
35+
Element(id, sizeLength, dataSize) {}
3736
BinaryElement(Id id, int sizeLength, offset_t dataSize, offset_t) :
38-
Element(id, sizeLength, dataSize)
39-
{
40-
}
41-
37+
Element(id, sizeLength, dataSize) {}
4238
explicit BinaryElement(Id id) :
43-
Element(id, 0, 0)
44-
{
45-
}
39+
Element(id, 0, 0) {}
40+
4641
const ByteVector &getValue() const { return value; }
47-
void setValue(const ByteVector &value) { this->value = value; }
42+
void setValue(const ByteVector &val) { value = val; }
4843
bool read(File &file) override;
4944
ByteVector render() override;
5045

taglib/matroska/ebml/ebmlelement.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
#include "tdebug.h"
3737
#include "tutils.h"
3838

39-
#include <cstdint>
40-
4139
using namespace TagLib;
4240

4341
#define RETURN_ELEMENT_FOR_CASE(eid) \
@@ -46,7 +44,7 @@ using namespace TagLib;
4644
std::unique_ptr<EBML::Element> EBML::Element::factory(File &file)
4745
{
4846
// Get the element ID
49-
offset_t offset = file.tell();
47+
const offset_t offset = file.tell();
5048
unsigned int uintId = readId(file);
5149
if(!uintId) {
5250
debug("Failed to parse EMBL ElementID");
@@ -138,12 +136,12 @@ unsigned int EBML::Element::readId(File &file)
138136
debug("Failed to read VINT size");
139137
return 0;
140138
}
141-
unsigned int nb_bytes = VINTSizeLength<4>(*buffer.begin());
142-
if(!nb_bytes)
139+
const unsigned int numBytes = VINTSizeLength<4>(*buffer.begin());
140+
if(!numBytes)
143141
return 0;
144-
if(nb_bytes > 1)
145-
buffer.append(file.readBlock(nb_bytes - 1));
146-
if(buffer.size() != nb_bytes) {
142+
if(numBytes > 1)
143+
buffer.append(file.readBlock(numBytes - 1));
144+
if(buffer.size() != numBytes) {
147145
debug("Failed to read VINT data");
148146
return 0;
149147
}
@@ -169,9 +167,9 @@ ByteVector EBML::Element::render()
169167

170168
ByteVector EBML::Element::renderId() const
171169
{
172-
int numBytes = idSize(id);
170+
const int numBytes = idSize(id);
173171
static const auto byteOrder = Utils::systemByteOrder();
174-
auto uintId = static_cast<uint32_t>(id);
172+
const auto uintId = static_cast<uint32_t>(id);
175173
uint32_t data = byteOrder == Utils::LittleEndian ? Utils::byteSwap(uintId) : uintId;
176174
return ByteVector(reinterpret_cast<char *>(&data) + (4 - numBytes), numBytes);
177175
}

taglib/matroska/ebml/ebmlelement.h

Lines changed: 211 additions & 212 deletions
Large diffs are not rendered by default.

taglib/matroska/ebml/ebmlfloatelement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ double EBML::FloatElement::getValueAsDouble(double defaultValue) const
4444

4545
bool EBML::FloatElement::read(File &file)
4646
{
47-
ByteVector buffer = file.readBlock(dataSize);
47+
const ByteVector buffer = file.readBlock(dataSize);
4848
if(buffer.size() != dataSize) {
4949
debug("Failed to read EBML Float element");
5050
return false;

taglib/matroska/ebml/ebmlfloatelement.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,12 @@ namespace TagLib {
4040
using FloatVariantType = std::variant<std::monostate, float, double>;
4141

4242
FloatElement(Id id, int sizeLength, offset_t dataSize) :
43-
Element(id, sizeLength, dataSize)
44-
{
45-
}
43+
Element(id, sizeLength, dataSize) {}
4644
FloatElement(Id id, int sizeLength, offset_t dataSize, offset_t) :
47-
Element(id, sizeLength, dataSize)
48-
{
49-
}
50-
45+
Element(id, sizeLength, dataSize) {}
5146
explicit FloatElement(Id id) :
52-
FloatElement(id, 0, 0)
53-
{
54-
}
47+
FloatElement(id, 0, 0) {}
48+
5549
FloatVariantType getValue() const { return value; }
5650
double getValueAsDouble(double defaultValue = 0.0) const;
5751
void setValue(FloatVariantType val) { value = val; }

taglib/matroska/ebml/ebmlmasterelement.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ using namespace TagLib;
2727

2828
EBML::MasterElement::~MasterElement() = default;
2929

30-
void EBML::MasterElement::appendElement(std::unique_ptr<Element>&& element)
30+
void EBML::MasterElement::appendElement(std::unique_ptr<Element> &&element)
3131
{
3232
elements.push_back(std::move(element));
3333
}
3434

3535
bool EBML::MasterElement::read(File &file)
3636
{
37-
offset_t maxOffset = file.tell() + dataSize;
37+
const offset_t maxOffset = file.tell() + dataSize;
3838
std::unique_ptr<Element> element;
3939
while((element = findNextElement(file, maxOffset))) {
4040
if(!element->read(file))
@@ -54,8 +54,8 @@ ByteVector EBML::MasterElement::render()
5454
buffer.append(renderVINT(dataSize, 0));
5555
buffer.append(data);
5656
if(minRenderSize) {
57-
auto bufferSize = buffer.size();
58-
if(minRenderSize >= bufferSize + MIN_VOID_ELEMENT_SIZE)
57+
if(const auto bufferSize = buffer.size();
58+
minRenderSize >= bufferSize + MIN_VOID_ELEMENT_SIZE)
5959
buffer.append(VoidElement::renderSize(minRenderSize - bufferSize));
6060
}
6161
return buffer;

taglib/matroska/ebml/ebmlmasterelement.h

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,46 @@
2323
#ifndef DO_NOT_DOCUMENT
2424

2525
#include "ebmlelement.h"
26-
#include "tbytevector.h"
27-
#include "tlist.h"
2826
#include "taglib.h"
27+
#include "tlist.h"
2928

30-
namespace TagLib::EBML {
31-
class MasterElement : public Element
32-
{
33-
public:
34-
MasterElement(Id id, int sizeLength, offset_t dataSize, offset_t offset) :
35-
Element(id, sizeLength, dataSize), offset(offset)
36-
{
37-
}
29+
namespace TagLib
30+
{
31+
class ByteVector;
3832

39-
explicit MasterElement(Id id) :
40-
Element(id, 0, 0), offset(0)
33+
namespace EBML {
34+
class MasterElement : public Element
4135
{
42-
}
43-
~MasterElement() override;
44-
offset_t getOffset() const { return offset; }
45-
bool read(File &file) override;
46-
ByteVector render() override;
47-
void appendElement(std::unique_ptr<Element> &&element);
48-
std::list<std::unique_ptr<Element>>::iterator begin() { return elements.begin(); }
49-
std::list<std::unique_ptr<Element>>::iterator end() { return elements.end(); }
50-
std::list<std::unique_ptr<Element>>::const_iterator begin() const { return elements.begin(); }
51-
std::list<std::unique_ptr<Element>>::const_iterator end() const { return elements.end(); }
52-
std::list<std::unique_ptr<Element>>::const_iterator cbegin() const { return elements.cbegin(); }
53-
std::list<std::unique_ptr<Element>>::const_iterator cend() const { return elements.cend(); }
54-
offset_t getPadding() const { return padding; }
55-
void setPadding(offset_t padding) { this->padding = padding; }
56-
offset_t getMinRenderSize() const { return minRenderSize; }
57-
void setMinRenderSize(offset_t minRenderSize) { this->minRenderSize = minRenderSize; }
36+
public:
37+
MasterElement(Id id, int sizeLength, offset_t dataSize, offset_t offset) :
38+
Element(id, sizeLength, dataSize), offset(offset) {}
39+
explicit MasterElement(Id id) :
40+
Element(id, 0, 0), offset(0) {}
41+
~MasterElement() override;
42+
43+
offset_t getOffset() const { return offset; }
44+
bool read(File &file) override;
45+
ByteVector render() override;
46+
void appendElement(std::unique_ptr<Element> &&element);
47+
std::list<std::unique_ptr<Element>>::iterator begin() { return elements.begin(); }
48+
std::list<std::unique_ptr<Element>>::iterator end() { return elements.end(); }
49+
std::list<std::unique_ptr<Element>>::const_iterator begin() const { return elements.begin(); }
50+
std::list<std::unique_ptr<Element>>::const_iterator end() const { return elements.end(); }
51+
std::list<std::unique_ptr<Element>>::const_iterator cbegin() const { return elements.cbegin(); }
52+
std::list<std::unique_ptr<Element>>::const_iterator cend() const { return elements.cend(); }
53+
offset_t getPadding() const { return padding; }
54+
void setPadding(offset_t numBytes) { padding = numBytes; }
55+
offset_t getMinRenderSize() const { return minRenderSize; }
56+
void setMinRenderSize(offset_t minimumSize) { minRenderSize = minimumSize; }
5857

59-
protected:
60-
offset_t offset;
61-
offset_t padding = 0;
62-
offset_t minRenderSize = 0;
63-
std::list<std::unique_ptr<Element>> elements;
64-
};
58+
protected:
59+
offset_t offset;
60+
offset_t padding = 0;
61+
offset_t minRenderSize = 0;
62+
std::list<std::unique_ptr<Element>> elements;
63+
};
6564

65+
}
6666
}
6767

6868
#endif

taglib/matroska/ebml/ebmlmkattachments.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
using namespace TagLib;
2929

30-
std::unique_ptr<Matroska::Attachments> EBML::MkAttachments::parse()
30+
std::unique_ptr<Matroska::Attachments> EBML::MkAttachments::parse() const
3131
{
3232
auto attachments = std::make_unique<Matroska::Attachments>();
3333
attachments->setOffset(offset);
@@ -42,17 +42,16 @@ std::unique_ptr<Matroska::Attachments> EBML::MkAttachments::parse()
4242
const String *mediaType = nullptr;
4343
const ByteVector *data = nullptr;
4444
Matroska::AttachedFile::UID uid = 0;
45-
auto attachedFile = element_cast<Id::MkAttachedFile>(element);
45+
const auto attachedFile = element_cast<Id::MkAttachedFile>(element);
4646
for(const auto &attachedFileChild : *attachedFile) {
47-
Id id = attachedFileChild->getId();
48-
if(id == Id::MkAttachedFileName)
49-
filename = &(element_cast<Id::MkAttachedFileName>(attachedFileChild)->getValue());
47+
if(const Id id = attachedFileChild->getId(); id == Id::MkAttachedFileName)
48+
filename = &element_cast<Id::MkAttachedFileName>(attachedFileChild)->getValue();
5049
else if(id == Id::MkAttachedFileData)
51-
data = &(element_cast<Id::MkAttachedFileData>(attachedFileChild)->getValue());
50+
data = &element_cast<Id::MkAttachedFileData>(attachedFileChild)->getValue();
5251
else if(id == Id::MkAttachedFileDescription)
53-
description = &(element_cast<Id::MkAttachedFileDescription>(attachedFileChild)->getValue());
52+
description = &element_cast<Id::MkAttachedFileDescription>(attachedFileChild)->getValue();
5453
else if(id == Id::MkAttachedFileMediaType)
55-
mediaType = &(element_cast<Id::MkAttachedFileMediaType>(attachedFileChild)->getValue());
54+
mediaType = &element_cast<Id::MkAttachedFileMediaType>(attachedFileChild)->getValue();
5655
else if(id == Id::MkAttachedFileUID)
5756
uid = element_cast<Id::MkAttachedFileUID>(attachedFileChild)->getValue();
5857
}

taglib/matroska/ebml/ebmlmkattachments.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#ifndef DO_NOT_DOCUMENT
2424

2525
#include "ebmlmasterelement.h"
26-
#include "ebmlutils.h"
2726
#include "taglib.h"
2827

2928
namespace TagLib {
@@ -35,18 +34,13 @@ namespace TagLib {
3534
{
3635
public:
3736
MkAttachments(int sizeLength, offset_t dataSize, offset_t offset) :
38-
MasterElement(Id::MkAttachments, sizeLength, dataSize, offset)
39-
{
40-
}
37+
MasterElement(Id::MkAttachments, sizeLength, dataSize, offset) {}
4138
MkAttachments(Id, int sizeLength, offset_t dataSize, offset_t offset) :
42-
MasterElement(Id::MkAttachments, sizeLength, dataSize, offset)
43-
{
44-
}
39+
MasterElement(Id::MkAttachments, sizeLength, dataSize, offset) {}
4540
MkAttachments() :
46-
MasterElement(Id::MkAttachments, 0, 0, 0)
47-
{
48-
}
49-
std::unique_ptr<Matroska::Attachments> parse();
41+
MasterElement(Id::MkAttachments, 0, 0, 0) {}
42+
43+
std::unique_ptr<Matroska::Attachments> parse() const;
5044
};
5145
}
5246
}

0 commit comments

Comments
 (0)