mirror of
https://github.com/taglib/taglib.git
synced 2025-06-04 01:28:21 -04:00
Fix issues reported by Clang Static Analyzer
Some deadcode.DeadStores. On Debian 12: CXXFLAGS=-I/usr/include/x86_64-linux-gnu/c++/12 \ cmake -DCMAKE_C_COMPILER=/usr/share/clang/scan-build-14/libexec/ccc-analyzer \ -DCMAKE_CXX_COMPILER=/usr/share/clang/scan-build-14/libexec/c++-analyzer \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ -DENABLE_CCACHE=ON -DBUILD_TESTING=ON -DBUILD_EXAMPLES=ON \ -DCMAKE_BUILD_TYPE=Debug ../taglib scan-build make
This commit is contained in:
parent
cf2bdce21d
commit
131918333b
@ -584,85 +584,91 @@ TagLib_Complex_Property_Attribute*** taglib_complex_property_get(
|
||||
TagLib_Complex_Property_Attribute ***propPtr = props;
|
||||
|
||||
for(const auto &variantMap : variantMaps) {
|
||||
TagLib_Complex_Property_Attribute **attrs = static_cast<TagLib_Complex_Property_Attribute **>(
|
||||
malloc(sizeof(TagLib_Complex_Property_Attribute *) * (variantMap.size() + 1)));
|
||||
TagLib_Complex_Property_Attribute *attr = static_cast<TagLib_Complex_Property_Attribute *>(
|
||||
malloc(sizeof(TagLib_Complex_Property_Attribute) * variantMap.size()));
|
||||
TagLib_Complex_Property_Attribute **attrPtr = attrs;
|
||||
for (const auto &[k, v] : variantMap) {
|
||||
attr->key = stringToCharArray(k);
|
||||
attr->value.size = 0;
|
||||
switch(v.type()) {
|
||||
case Variant::Void:
|
||||
attr->value.type = TagLib_Variant_Void;
|
||||
attr->value.value.stringValue = NULL;
|
||||
break;
|
||||
case Variant::Bool:
|
||||
attr->value.type = TagLib_Variant_Bool;
|
||||
attr->value.value.boolValue = v.value<bool>();
|
||||
break;
|
||||
case Variant::Int:
|
||||
attr->value.type = TagLib_Variant_Int;
|
||||
attr->value.value.intValue = v.value<int>();
|
||||
break;
|
||||
case Variant::UInt:
|
||||
attr->value.type = TagLib_Variant_UInt;
|
||||
attr->value.value.uIntValue = v.value<unsigned int>();
|
||||
break;
|
||||
case Variant::LongLong:
|
||||
attr->value.type = TagLib_Variant_LongLong;
|
||||
attr->value.value.longLongValue = v.value<long long>();
|
||||
break;
|
||||
case Variant::ULongLong:
|
||||
attr->value.type = TagLib_Variant_ULongLong;
|
||||
attr->value.value.uLongLongValue = v.value<unsigned long long>();
|
||||
break;
|
||||
case Variant::Double:
|
||||
attr->value.type = TagLib_Variant_Double;
|
||||
attr->value.value.doubleValue = v.value<double>();
|
||||
break;
|
||||
case Variant::String: {
|
||||
attr->value.type = TagLib_Variant_String;
|
||||
auto str = v.value<String>();
|
||||
attr->value.value.stringValue = stringToCharArray(str);
|
||||
attr->value.size = str.size();
|
||||
break;
|
||||
}
|
||||
case Variant::StringList: {
|
||||
attr->value.type = TagLib_Variant_StringList;
|
||||
StringList strs = v.value<StringList>();
|
||||
auto strPtr = static_cast<char **>(malloc(sizeof(char *) * (strs.size() + 1)));
|
||||
attr->value.value.stringListValue = strPtr;
|
||||
attr->value.size = strs.size();
|
||||
for(const auto &str : strs) {
|
||||
*strPtr++ = stringToCharArray(str);
|
||||
if(!variantMap.isEmpty()) {
|
||||
TagLib_Complex_Property_Attribute **attrs = static_cast<TagLib_Complex_Property_Attribute **>(
|
||||
malloc(sizeof(TagLib_Complex_Property_Attribute *) * (variantMap.size() + 1)));
|
||||
TagLib_Complex_Property_Attribute *attr = static_cast<TagLib_Complex_Property_Attribute *>(
|
||||
malloc(sizeof(TagLib_Complex_Property_Attribute) * variantMap.size()));
|
||||
TagLib_Complex_Property_Attribute **attrPtr = attrs;
|
||||
// The next assignment is redundant to silence the clang analyzer,
|
||||
// it is done at the end of the loop, which must be entered because
|
||||
// variantMap is not empty.
|
||||
*attrPtr = attr;
|
||||
for(const auto &[k, v] : variantMap) {
|
||||
attr->key = stringToCharArray(k);
|
||||
attr->value.size = 0;
|
||||
switch(v.type()) {
|
||||
case Variant::Void:
|
||||
attr->value.type = TagLib_Variant_Void;
|
||||
attr->value.value.stringValue = NULL;
|
||||
break;
|
||||
case Variant::Bool:
|
||||
attr->value.type = TagLib_Variant_Bool;
|
||||
attr->value.value.boolValue = v.value<bool>();
|
||||
break;
|
||||
case Variant::Int:
|
||||
attr->value.type = TagLib_Variant_Int;
|
||||
attr->value.value.intValue = v.value<int>();
|
||||
break;
|
||||
case Variant::UInt:
|
||||
attr->value.type = TagLib_Variant_UInt;
|
||||
attr->value.value.uIntValue = v.value<unsigned int>();
|
||||
break;
|
||||
case Variant::LongLong:
|
||||
attr->value.type = TagLib_Variant_LongLong;
|
||||
attr->value.value.longLongValue = v.value<long long>();
|
||||
break;
|
||||
case Variant::ULongLong:
|
||||
attr->value.type = TagLib_Variant_ULongLong;
|
||||
attr->value.value.uLongLongValue = v.value<unsigned long long>();
|
||||
break;
|
||||
case Variant::Double:
|
||||
attr->value.type = TagLib_Variant_Double;
|
||||
attr->value.value.doubleValue = v.value<double>();
|
||||
break;
|
||||
case Variant::String: {
|
||||
attr->value.type = TagLib_Variant_String;
|
||||
auto str = v.value<String>();
|
||||
attr->value.value.stringValue = stringToCharArray(str);
|
||||
attr->value.size = str.size();
|
||||
break;
|
||||
}
|
||||
*strPtr = NULL;
|
||||
break;
|
||||
case Variant::StringList: {
|
||||
attr->value.type = TagLib_Variant_StringList;
|
||||
StringList strs = v.value<StringList>();
|
||||
auto strPtr = static_cast<char **>(malloc(sizeof(char *) * (strs.size() + 1)));
|
||||
attr->value.value.stringListValue = strPtr;
|
||||
attr->value.size = strs.size();
|
||||
for(const auto &str : strs) {
|
||||
*strPtr++ = stringToCharArray(str);
|
||||
}
|
||||
*strPtr = NULL;
|
||||
break;
|
||||
}
|
||||
case Variant::ByteVector: {
|
||||
attr->value.type = TagLib_Variant_ByteVector;
|
||||
const ByteVector data = v.value<ByteVector>();
|
||||
auto bytePtr = static_cast<char *>(malloc(data.size()));
|
||||
attr->value.value.byteVectorValue = bytePtr;
|
||||
attr->value.size = data.size();
|
||||
::memcpy(bytePtr, data.data(), data.size());
|
||||
break;
|
||||
}
|
||||
case Variant::ByteVectorList:
|
||||
case Variant::VariantList:
|
||||
case Variant::VariantMap: {
|
||||
attr->value.type = TagLib_Variant_String;
|
||||
std::stringstream ss;
|
||||
ss << v;
|
||||
attr->value.value.stringValue = stringToCharArray(ss.str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
*attrPtr++ = attr++;
|
||||
}
|
||||
case Variant::ByteVector: {
|
||||
attr->value.type = TagLib_Variant_ByteVector;
|
||||
const ByteVector data = v.value<ByteVector>();
|
||||
auto bytePtr = static_cast<char *>(malloc(data.size()));
|
||||
attr->value.value.byteVectorValue = bytePtr;
|
||||
attr->value.size = data.size();
|
||||
::memcpy(bytePtr, data.data(), data.size());
|
||||
break;
|
||||
}
|
||||
case Variant::ByteVectorList:
|
||||
case Variant::VariantList:
|
||||
case Variant::VariantMap: {
|
||||
attr->value.type = TagLib_Variant_String;
|
||||
std::stringstream ss;
|
||||
ss << v;
|
||||
attr->value.value.stringValue = stringToCharArray(ss.str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
*attrPtr++ = attr++;
|
||||
*attrPtr = NULL;
|
||||
*propPtr++ = attrs;
|
||||
}
|
||||
*attrPtr++ = NULL;
|
||||
*propPtr++ = attrs;
|
||||
}
|
||||
*propPtr = NULL;
|
||||
return props;
|
||||
|
@ -160,25 +160,30 @@ void Mod::File::read(bool)
|
||||
seek(0);
|
||||
READ_STRING(d->tag.setTitle, 20);
|
||||
|
||||
offset_t pos = 20;
|
||||
StringList comment;
|
||||
for(unsigned int i = 0; i < instruments; ++ i) {
|
||||
READ_STRING_AS(instrumentName, 22);
|
||||
// value in words, * 2 (<< 1) for bytes:
|
||||
READ_U16B_AS(sampleLength);
|
||||
// skip unused data
|
||||
pos += 22 + 2 + 1 + 1 + 2 + 2;
|
||||
seek(pos);
|
||||
|
||||
READ_BYTE_AS(fineTuneByte);
|
||||
int fineTune = fineTuneByte & 0xF;
|
||||
// > 7 means negative value
|
||||
if(fineTune > 7) fineTune -= 16;
|
||||
// // value in words, * 2 (<< 1) for bytes:
|
||||
// READ_U16B_AS(sampleLength);
|
||||
|
||||
READ_BYTE_AS(volume);
|
||||
if(volume > 64) volume = 64;
|
||||
// volume in decibels: 20 * log10(volume / 64)
|
||||
// READ_BYTE_AS(fineTuneByte);
|
||||
// int fineTune = fineTuneByte & 0xF;
|
||||
// // > 7 means negative value
|
||||
// if(fineTune > 7) fineTune -= 16;
|
||||
|
||||
// value in words, * 2 (<< 1) for bytes:
|
||||
READ_U16B_AS(repeatStart);
|
||||
// value in words, * 2 (<< 1) for bytes:
|
||||
READ_U16B_AS(repatLength);
|
||||
// READ_BYTE_AS(volume);
|
||||
// if(volume > 64) volume = 64;
|
||||
// // volume in decibels: 20 * log10(volume / 64)
|
||||
|
||||
// // value in words, * 2 (<< 1) for bytes:
|
||||
// READ_U16B_AS(repeatStart);
|
||||
// // value in words, * 2 (<< 1) for bytes:
|
||||
// READ_U16B_AS(repeatLength);
|
||||
|
||||
comment.append(instrumentName);
|
||||
}
|
||||
|
@ -221,7 +221,6 @@ void MPC::Properties::readSV8(File *file, offset_t streamLength)
|
||||
}
|
||||
|
||||
const unsigned short flags = data.toUShort(pos, true);
|
||||
pos += 2;
|
||||
|
||||
d->sampleRate = sftable[(flags >> 13) & 0x07];
|
||||
d->channels = ((flags >> 4) & 0x0F) + 1;
|
||||
|
@ -122,13 +122,13 @@ void Opus::Properties::read(File *file)
|
||||
|
||||
// *Input Sample Rate* (32 bits, unsigned, little endian)
|
||||
d->inputSampleRate = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
// pos += 4;
|
||||
|
||||
// *Output Gain* (16 bits, signed, little endian)
|
||||
pos += 2;
|
||||
// pos += 2;
|
||||
|
||||
// *Channel Mapping Family* (8 bits, unsigned)
|
||||
pos += 1;
|
||||
// pos += 1;
|
||||
|
||||
const Ogg::PageHeader *first = file->firstPageHeader();
|
||||
const Ogg::PageHeader *last = file->lastPageHeader();
|
||||
|
@ -141,8 +141,8 @@ void Speex::Properties::read(File *file)
|
||||
|
||||
// vbr; /**< 1 for a VBR encoding, 0 otherwise */
|
||||
d->vbr = data.toUInt(pos, false) == 1;
|
||||
pos += 4;
|
||||
|
||||
// pos += 4;
|
||||
// frames_per_packet; /**< Number of frames stored per Ogg packet */
|
||||
// unsigned int framesPerPacket = data.mid(pos, 4).toUInt(false);
|
||||
|
||||
|
@ -145,7 +145,6 @@ void Vorbis::Properties::read(File *file)
|
||||
pos += 4;
|
||||
|
||||
d->bitrateMinimum = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
// Find the length of the file. See http://wiki.xiph.org/VorbisStreamLength/
|
||||
// for my notes on the topic.
|
||||
|
@ -141,7 +141,6 @@ void TrueAudio::Properties::read(const ByteVector &data, offset_t streamLength)
|
||||
pos += 4;
|
||||
|
||||
d->sampleFrames = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
if(d->sampleFrames > 0 && d->sampleRate > 0) {
|
||||
const double length = d->sampleFrames * 1000.0 / d->sampleRate;
|
||||
|
@ -24,8 +24,8 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "tdebug.h"
|
||||
#include "tpropertymap.h"
|
||||
@ -307,6 +307,7 @@ public:
|
||||
dynamic_cast<TagLib::ID3v2::AttachedPictureFrame *>(factory->createFrame(data, &header));
|
||||
|
||||
CPPUNIT_ASSERT(frame);
|
||||
assert(frame != nullptr); // to silence the clang analyzer
|
||||
CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), frame->mimeType());
|
||||
CPPUNIT_ASSERT_EQUAL(ID3v2::AttachedPictureFrame::FileIcon, frame->type());
|
||||
CPPUNIT_ASSERT_EQUAL(String("d"), frame->description());
|
||||
@ -1126,6 +1127,7 @@ public:
|
||||
ID3v2::AttachedPictureFrame *frame
|
||||
= dynamic_cast<TagLib::ID3v2::AttachedPictureFrame*>(f.ID3v2Tag()->frameListMap()["APIC"].front());
|
||||
CPPUNIT_ASSERT(frame);
|
||||
assert(frame != nullptr); // to silence the clang analyzer
|
||||
CPPUNIT_ASSERT_EQUAL(String("image/bmp"), frame->mimeType());
|
||||
CPPUNIT_ASSERT_EQUAL(ID3v2::AttachedPictureFrame::Other, frame->type());
|
||||
CPPUNIT_ASSERT_EQUAL(String(""), frame->description());
|
||||
@ -1148,6 +1150,7 @@ public:
|
||||
ID3v2::UrlLinkFrame *frame =
|
||||
dynamic_cast<TagLib::ID3v2::UrlLinkFrame*>(f.ID3v2Tag()->frameListMap()["W000"].front());
|
||||
CPPUNIT_ASSERT(frame);
|
||||
assert(frame != nullptr); // to silence the clang analyzer
|
||||
CPPUNIT_ASSERT_EQUAL(String("lukas.lalinsky@example.com____"), frame->url());
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <cassert>
|
||||
#include "tstringlist.h"
|
||||
#include "itfile.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
@ -106,6 +107,7 @@ private:
|
||||
|
||||
CPPUNIT_ASSERT(nullptr != p);
|
||||
CPPUNIT_ASSERT(nullptr != t);
|
||||
assert(p != nullptr); // to silence the clang analyzer
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 0, p->lengthInSeconds());
|
||||
CPPUNIT_ASSERT_EQUAL( 0, p->bitrate());
|
||||
|
@ -23,6 +23,7 @@
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <cassert>
|
||||
#include "tpropertymap.h"
|
||||
#include "modfile.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
@ -112,6 +113,7 @@ private:
|
||||
|
||||
CPPUNIT_ASSERT(nullptr != p);
|
||||
CPPUNIT_ASSERT(nullptr != t);
|
||||
assert(p != nullptr); // to silence the clang analyzer
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->lengthInSeconds());
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->bitrate());
|
||||
|
@ -23,6 +23,7 @@
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <cassert>
|
||||
#include "s3mfile.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "utils.h"
|
||||
@ -97,6 +98,7 @@ private:
|
||||
|
||||
CPPUNIT_ASSERT(nullptr != p);
|
||||
CPPUNIT_ASSERT(nullptr != t);
|
||||
assert(p != nullptr); // to silence the clang analyzer
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 0, p->lengthInSeconds());
|
||||
CPPUNIT_ASSERT_EQUAL( 0, p->bitrate());
|
||||
|
@ -23,6 +23,7 @@
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <cassert>
|
||||
#include "xmfile.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "utils.h"
|
||||
@ -129,6 +130,7 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT(nullptr != p);
|
||||
CPPUNIT_ASSERT(nullptr != t);
|
||||
assert(p != nullptr); // to silence the clang analyzer
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->lengthInSeconds());
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->bitrate());
|
||||
@ -175,6 +177,7 @@ private:
|
||||
|
||||
CPPUNIT_ASSERT(nullptr != p);
|
||||
CPPUNIT_ASSERT(nullptr != t);
|
||||
assert(p != nullptr); // to silence the clang analyzer
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->lengthInSeconds());
|
||||
CPPUNIT_ASSERT_EQUAL(0, p->bitrate());
|
||||
|
Loading…
x
Reference in New Issue
Block a user