From 9ceeb09b5fc5a18f9f4d515fe2c134828300a725 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 26 Nov 2024 21:56:24 -0800 Subject: [PATCH] gcc: fix various Wnrvo warnings GCC cannot elide copies with multiple returns. Signed-off-by: Rosen Penev --- .../mpeg/id3v2/frames/textidentificationframe.cpp | 8 +++++--- taglib/mpeg/id3v2/id3v2frame.cpp | 15 ++++++++------- taglib/mpeg/id3v2/id3v2synchdata.cpp | 5 +++-- taglib/ogg/oggfile.cpp | 11 +++++++---- taglib/ogg/oggpage.cpp | 8 +++++--- taglib/tagutils.cpp | 5 +++-- taglib/toolkit/tbytevectorstream.cpp | 5 +++-- taglib/toolkit/tfilestream.cpp | 7 ++++--- 8 files changed, 38 insertions(+), 26 deletions(-) diff --git a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp index aa78d563..6d9f4828 100644 --- a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp +++ b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp @@ -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; } diff --git a/taglib/mpeg/id3v2/id3v2frame.cpp b/taglib/mpeg/id3v2/id3v2frame.cpp index 1662293a..bdfa2c13 100644 --- a/taglib/mpeg/id3v2/id3v2frame.cpp +++ b/taglib/mpeg/id3v2/id3v2frame.cpp @@ -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; @@ -299,10 +300,10 @@ 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"); } @@ -310,11 +311,13 @@ ByteVector Frame::fieldData(const ByteVector &frameData) const 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) @@ -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 @@ -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; } diff --git a/taglib/mpeg/id3v2/id3v2synchdata.cpp b/taglib/mpeg/id3v2/id3v2synchdata.cpp index e9fafde3..fd508e95 100644 --- a/taglib/mpeg/id3v2/id3v2synchdata.cpp +++ b/taglib/mpeg/id3v2/id3v2synchdata.cpp @@ -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(); diff --git a/taglib/ogg/oggfile.cpp b/taglib/ogg/oggfile.cpp index 29f1803a..d680ea93 100644 --- a/taglib/ogg/oggfile.cpp +++ b/taglib/ogg/oggfile.cpp @@ -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. @@ -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; diff --git a/taglib/ogg/oggpage.cpp b/taglib/ogg/oggpage.cpp index a4fa7aea..89463c55 100644 --- a/taglib/ogg/oggpage.cpp +++ b/taglib/ogg/oggpage.cpp @@ -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()); diff --git a/taglib/tagutils.cpp b/taglib/tagutils.cpp index c11c8b69..73a77699 100644 --- a/taglib/tagutils.cpp +++ b/taglib/tagutils.cpp @@ -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; @@ -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) diff --git a/taglib/toolkit/tbytevectorstream.cpp b/taglib/toolkit/tbytevectorstream.cpp index f65f591d..80ca714d 100644 --- a/taglib/toolkit/tbytevectorstream.cpp +++ b/taglib/toolkit/tbytevectorstream.cpp @@ -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(d->position), + v = d->data.mid(static_cast(d->position), static_cast(length)); d->position += v.size(); return v; diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 9ace7c85..4d8942c2 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -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(FileStream::length()); @@ -223,7 +224,7 @@ ByteVector FileStream::readBlock(size_t length) } } - ByteVector buffer(static_cast(length)); + buffer = ByteVector(static_cast(length)); const size_t count = readFile(d->file, buffer); buffer.resize(static_cast(count));