Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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
8 changes: 5 additions & 3 deletions taglib/mpeg/id3v2/frames/textidentificationframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,12 @@ UserTextIdentificationFrame *UserTextIdentificationFrame::find(

String UserTextIdentificationFrame::txxxToKey(const String &description)
{
const String d = description.upper();
String d = description.upper();
for(const auto &[o, t] : txxxFrameTranslation) {
if(d == o)
return t;
if(d == o) {
d = t;
break;
}
}
return d;
}
Expand Down
15 changes: 8 additions & 7 deletions taglib/mpeg/id3v2/id3v2frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ void Frame::parse(const ByteVector &data)

ByteVector Frame::fieldData(const ByteVector &frameData) const
{
ByteVector outData;
unsigned int headerSize = d->header->size();

unsigned int frameDataOffset = headerSize;
Expand All @@ -299,22 +300,24 @@ ByteVector Frame::fieldData(const ByteVector &frameData) const
if(zlib::isAvailable() && d->header->compression() && !d->header->encryption()) {
if(frameData.size() <= frameDataOffset) {
debug("Compressed frame doesn't have enough data to decode");
return ByteVector();
return outData;
}

const ByteVector outData = zlib::decompress(frameData.mid(frameDataOffset));
outData = zlib::decompress(frameData.mid(frameDataOffset));
if(!outData.isEmpty() && frameDataLength != outData.size()) {
debug("frameDataLength does not match the data length returned by zlib");
}

return outData;
}

return frameData.mid(frameDataOffset, frameDataLength);
outData = frameData.mid(frameDataOffset, frameDataLength);
return outData;
}

String Frame::readStringField(const ByteVector &data, String::Type encoding, int *position)
{
String str;
int start = 0;

if(!position)
Expand All @@ -325,9 +328,8 @@ String Frame::readStringField(const ByteVector &data, String::Type encoding, int
int end = data.find(delimiter, *position, delimiter.size());

if(end < *position)
return String();
return str;

String str;
if(encoding == String::Latin1)
str = Tag::latin1StringHandler()->parse(data.mid(*position, end - *position));
else
Expand Down Expand Up @@ -362,13 +364,12 @@ String::Type Frame::checkTextEncoding(const StringList &fields, String::Type enc

PropertyMap Frame::asProperties() const
{
PropertyMap m;
if(dynamic_cast< const UnknownFrame *>(this)) {
PropertyMap m;
m.addUnsupportedData("UNKNOWN/" + frameID());
return m;
}
const ByteVector &id = frameID();
PropertyMap m;
m.addUnsupportedData(id);
return m;
}
Expand Down
5 changes: 3 additions & 2 deletions taglib/mpeg/id3v2/id3v2synchdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ ByteVector SynchData::fromUInt(unsigned int value)

ByteVector SynchData::decode(const ByteVector &data)
{
ByteVector result;
if(data.isEmpty()) {
return ByteVector();
return result;
}

// We have this optimized method instead of using ByteVector::replace(),
// since it makes a great difference when decoding huge unsynchronized frames.

ByteVector result(data.size());
result = ByteVector(data.size());

auto src = data.begin();
auto dst = result.begin();
Expand Down
11 changes: 7 additions & 4 deletions taglib/ogg/oggfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,21 @@ Ogg::File::~File() = default;

ByteVector Ogg::File::packet(unsigned int i)
{
ByteVector packet;
// Check to see if we're called setPacket() for this packet since the last
// save:

if(d->dirtyPackets.contains(i))
return d->dirtyPackets[i];
if(d->dirtyPackets.contains(i)) {
packet = d->dirtyPackets[i];
return packet;
}

// If we haven't indexed the page where the packet we're interested in starts,
// begin reading pages until we have.

if(!readPages(i)) {
debug("Ogg::File::packet() -- Could not find the requested packet.");
return ByteVector();
return packet;
}

// Look for the first page in which the requested packet starts.
Expand All @@ -94,7 +97,7 @@ ByteVector Ogg::File::packet(unsigned int i)
// the pages' packet data until we hit a page that either does not end with the
// packet that we're fetching or where the last packet is complete.

ByteVector packet = (*it)->packets()[i - (*it)->firstPacketIndex()];
packet = (*it)->packets()[i - (*it)->firstPacketIndex()];

while(nextPacketIndex(*it) <= i) {
++it;
Expand Down
8 changes: 5 additions & 3 deletions taglib/ogg/oggpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,13 @@ unsigned int Ogg::Page::packetCount() const

ByteVectorList Ogg::Page::packets() const
{
if(!d->packets.isEmpty())
return d->packets;

ByteVectorList l;

if(!d->packets.isEmpty()) {
l = d->packets;
return l;
}

if(d->file && d->header.isValid()) {

d->file->seek(d->fileOffset + d->header.size());
Expand Down
5 changes: 3 additions & 2 deletions taglib/tagutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ offset_t Utils::findAPE(File *file, offset_t id3v1Location)
ByteVector TagLib::Utils::readHeader(IOStream *stream, unsigned int length,
bool skipID3v2, offset_t *headerOffset)
{
ByteVector header;
if(!stream || !stream->isOpen())
return ByteVector();
return header;

const offset_t originalPosition = stream->tell();
offset_t bufferOffset = 0;
Expand All @@ -106,7 +107,7 @@ ByteVector TagLib::Utils::readHeader(IOStream *stream, unsigned int length,
}

stream->seek(bufferOffset);
const ByteVector header = stream->readBlock(length);
header = stream->readBlock(length);
stream->seek(originalPosition);

if(headerOffset)
Expand Down
5 changes: 3 additions & 2 deletions taglib/toolkit/tbytevectorstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ FileName ByteVectorStream::name() const

ByteVector ByteVectorStream::readBlock(size_t length)
{
ByteVector v;
if(length == 0)
return ByteVector();
return v;

ByteVector v = d->data.mid(static_cast<unsigned int>(d->position),
v = d->data.mid(static_cast<unsigned int>(d->position),
static_cast<unsigned int>(length));
d->position += v.size();
return v;
Expand Down
7 changes: 4 additions & 3 deletions taglib/toolkit/tfilestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,14 @@ FileName FileStream::name() const

ByteVector FileStream::readBlock(size_t length)
{
ByteVector buffer;
if(!isOpen()) {
debug("FileStream::readBlock() -- invalid file.");
return ByteVector();
return buffer;
}

if(length == 0)
return ByteVector();
return buffer;

if(length > bufferSize()) {
if(const auto streamLength = static_cast<size_t>(FileStream::length());
Expand All @@ -223,7 +224,7 @@ ByteVector FileStream::readBlock(size_t length)
}
}

ByteVector buffer(static_cast<unsigned int>(length));
buffer = ByteVector(static_cast<unsigned int>(length));

const size_t count = readFile(d->file, buffer);
buffer.resize(static_cast<unsigned int>(count));
Expand Down