]> granicus.if.org Git - taglib/commitdiff
Avoid using ByteVector::null where an empty vector is required.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Thu, 19 Nov 2015 01:52:46 +0000 (10:52 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Thu, 19 Nov 2015 01:52:46 +0000 (10:52 +0900)
ByteVector::null is not necessarily be empty or remains the same instance.
Using it in a public header may lead to a linkage error.

16 files changed:
taglib/asf/asffile.cpp
taglib/asf/asfpicture.cpp
taglib/mp4/mp4tag.cpp
taglib/mpeg/id3v2/id3v2frame.cpp
taglib/ogg/oggfile.cpp
taglib/riff/rifffile.cpp
taglib/toolkit/tbytevectorlist.cpp
taglib/toolkit/tbytevectorstream.cpp
taglib/toolkit/tfile.cpp
taglib/toolkit/tfile.h
taglib/toolkit/tfilestream.cpp
taglib/toolkit/tstring.cpp
tests/test_apetag.cpp
tests/test_bytevector.cpp
tests/test_bytevectorstream.cpp
tests/test_id3v2.cpp

index e8a68d812d3fa65f203443601e35d597ee48156a..02fe83c3eaed32408e2ad2dc1b7bccab327a92bc 100644 (file)
@@ -196,7 +196,7 @@ void ASF::File::FilePrivate::BaseObject::parse(ASF::File *file, unsigned int siz
   if(size > 24 && size <= (unsigned int)(file->length()))
     data = file->readBlock(size - 24);
   else
-    data = ByteVector::null;
+    data = ByteVector();
 }
 
 ByteVector ASF::File::FilePrivate::BaseObject::render(ASF::File * /*file*/)
@@ -312,7 +312,7 @@ ByteVector ASF::File::FilePrivate::ExtendedContentDescriptionObject::render(ASF:
 {
   data.clear();
   data.append(ByteVector::fromShort(attributeData.size(), false));
-  data.append(attributeData.toByteVector(ByteVector::null));
+  data.append(attributeData.toByteVector(""));
   return BaseObject::render(file);
 }
 
@@ -336,7 +336,7 @@ ByteVector ASF::File::FilePrivate::MetadataObject::render(ASF::File *file)
 {
   data.clear();
   data.append(ByteVector::fromShort(attributeData.size(), false));
-  data.append(attributeData.toByteVector(ByteVector::null));
+  data.append(attributeData.toByteVector(""));
   return BaseObject::render(file);
 }
 
@@ -360,7 +360,7 @@ ByteVector ASF::File::FilePrivate::MetadataLibraryObject::render(ASF::File *file
 {
   data.clear();
   data.append(ByteVector::fromShort(attributeData.size(), false));
-  data.append(attributeData.toByteVector(ByteVector::null));
+  data.append(attributeData.toByteVector(""));
   return BaseObject::render(file);
 }
 
index cdf6e758517224ca3feb451e2c937a918eea3bd6..f772052f5152a8c9a532b9e562a5ab9de8882740 100644 (file)
@@ -132,7 +132,8 @@ ASF::Picture& ASF::Picture::operator=(const ASF::Picture& other)
 ByteVector ASF::Picture::render() const
 {
   if(!isValid())
-    return ByteVector::null;
+    return ByteVector();
+
   return
     ByteVector((char)d->type) +
     ByteVector::fromUInt(d->picture.size(), false) +
index 52f669063d024840778f75f55cb1c76e00c79465..47c802ce644962f4dde034c697e54b757193b4b5 100644 (file)
@@ -428,7 +428,7 @@ MP4::Tag::renderFreeForm(const String &name, const MP4::Item &item) const
   StringList header = StringList::split(name, ":");
   if(header.size() != 3) {
     debug("MP4: Invalid free-form item name \"" + name + "\"");
-    return ByteVector::null;
+    return ByteVector();
   }
   ByteVector data;
   data.append(renderAtom("mean", ByteVector::fromUInt(0) + header[1].data(String::UTF8)));
index a130d0030982953fe19c014d4331978438131c2a..91eec32845f8f2f7916daf5d40c1517efc277a02 100644 (file)
@@ -170,7 +170,7 @@ ByteVector Frame::frameID() const
   if(d->header)
     return d->header->frameID();
   else
-    return ByteVector::null;
+    return ByteVector();
 }
 
 TagLib::uint Frame::size() const
index dfd81ec6459b013c1cd7444407c873d836d3b091..82781412df4f7445a1c6530bb4bc6398937d0f08 100644 (file)
@@ -92,7 +92,7 @@ ByteVector Ogg::File::packet(uint i)
   while(d->packetToPageMap.size() <= i) {
     if(!nextPage()) {
       debug("Ogg::File::packet() -- Could not find the requested packet.");
-      return ByteVector::null;
+      return ByteVector();
     }
   }
 
@@ -125,7 +125,7 @@ ByteVector Ogg::File::packet(uint i)
     if(pageIndex == d->pages.size()) {
       if(!nextPage()) {
         debug("Ogg::File::packet() -- Could not find the requested packet.");
-        return ByteVector::null;
+        return ByteVector();
       }
     }
     d->currentPacketPage = d->pages[pageIndex];
index efd4f642636af456c2f36e5c099d478e0bccbbc1..7d427a46594d8a34edc7faf2c2b94c941ee79c20 100644 (file)
@@ -117,7 +117,7 @@ TagLib::uint RIFF::File::chunkPadding(uint i) const
 ByteVector RIFF::File::chunkName(uint i) const
 {
   if(i >= chunkCount())
-    return ByteVector::null;
+    return ByteVector();
 
   return d->chunks[i].name;
 }
@@ -125,7 +125,7 @@ ByteVector RIFF::File::chunkName(uint i) const
 ByteVector RIFF::File::chunkData(uint i)
 {
   if(i >= chunkCount())
-    return ByteVector::null;
+    return ByteVector();
 
   seek(d->chunks[i].offset);
   return readBlock(d->chunks[i].size);
index 7ea893f11b8dad7699883ad3c82b3e0b36c0e4a2..40e088d86bcc10d69c2bfdc43ef4342de596d14d 100644 (file)
@@ -55,7 +55,7 @@ ByteVectorList ByteVectorList::split(const ByteVector &v, const ByteVector &patt
     if(offset - previousOffset >= 1)
       l.append(v.mid(previousOffset, offset - previousOffset));
     else
-      l.append(ByteVector::null);
+      l.append(ByteVector());
 
     previousOffset = offset + pattern.size();
   }
index dc480a2637c3e8d7d18a027b1865d5fa7fe46595..230f7c99ec7c7e409e67a721ecd5f291acb15f0c 100644 (file)
@@ -71,7 +71,7 @@ FileName ByteVectorStream::name() const
 ByteVector ByteVectorStream::readBlock(ulong length)
 {
   if(length == 0)
-    return ByteVector::null;
+    return ByteVector();
 
   ByteVector v = d->data.mid(d->position, length);
   d->position += v.size();
index a01c346080dee07c4f8166255f844c1e1736deb2..2fca74451a0ae0190eb2d691bdc20f002d2134f4 100644 (file)
@@ -289,7 +289,7 @@ long File::find(const ByteVector &pattern, long fromOffset, const ByteVector &be
       }
     }
 
-    if(!before.isNull() && beforePreviousPartialMatch >= 0 && int(bufferSize()) > beforePreviousPartialMatch) {
+    if(!before.isEmpty() && beforePreviousPartialMatch >= 0 && int(bufferSize()) > beforePreviousPartialMatch) {
       const int beforeOffset = (bufferSize() - beforePreviousPartialMatch);
       if(buffer.containsAt(before, 0, beforeOffset)) {
         seek(originalPosition);
@@ -305,7 +305,7 @@ long File::find(const ByteVector &pattern, long fromOffset, const ByteVector &be
       return bufferOffset + location;
     }
 
-    if(!before.isNull() && buffer.find(before) >= 0) {
+    if(!before.isEmpty() && buffer.find(before) >= 0) {
       seek(originalPosition);
       return -1;
     }
@@ -314,7 +314,7 @@ long File::find(const ByteVector &pattern, long fromOffset, const ByteVector &be
 
     previousPartialMatch = buffer.endsWithPartialMatch(pattern);
 
-    if(!before.isNull())
+    if(!before.isEmpty())
       beforePreviousPartialMatch = buffer.endsWithPartialMatch(before);
 
     bufferOffset += bufferSize();
@@ -387,7 +387,7 @@ long File::rfind(const ByteVector &pattern, long fromOffset, const ByteVector &b
       return bufferOffset + location;
     }
 
-    if(!before.isNull() && buffer.find(before) >= 0) {
+    if(!before.isEmpty() && buffer.find(before) >= 0) {
       seek(originalPosition);
       return -1;
     }
index fe4efcbaa18780855c50e96f15e5413386ca2b51..7784068497a4260742f946f4a1cebcb77c992a63 100644 (file)
@@ -165,7 +165,7 @@ namespace TagLib {
      */
     long find(const ByteVector &pattern,
               long fromOffset = 0,
-              const ByteVector &before = ByteVector::null);
+              const ByteVector &before = ByteVector());
 
     /*!
      * Returns the offset in the file that \a pattern occurs at or -1 if it can
@@ -181,7 +181,7 @@ namespace TagLib {
      */
     long rfind(const ByteVector &pattern,
                long fromOffset = 0,
-               const ByteVector &before = ByteVector::null);
+               const ByteVector &before = ByteVector());
 
     /*!
      * Insert \a data at position \a start in the file overwriting \a replace
index 65f37d52e888afa88b7f616fa20a7494cfc8082d..0ced6c79c275733c466c3cc092ca4f6d7308c033 100644 (file)
@@ -176,11 +176,11 @@ ByteVector FileStream::readBlock(ulong length)
 {
   if(!isOpen()) {
     debug("FileStream::readBlock() -- invalid file.");
-    return ByteVector::null;
+    return ByteVector();
   }
 
   if(length == 0)
-    return ByteVector::null;
+    return ByteVector();
 
   const ulong streamLength = static_cast<ulong>(FileStream::length());
   if(length > bufferSize() && length > streamLength)
index d623d2376668d34c961baad973c0c802a265e74d..479b406919e170643d5c185e5f217075584251e9 100644 (file)
@@ -426,7 +426,7 @@ ByteVector String::data(Type t) const
       return v;
     }
     else {
-      return ByteVector::null;
+      return ByteVector();
     }
   case UTF16:
     {
@@ -472,7 +472,7 @@ ByteVector String::data(Type t) const
   default:
     {
       debug("String::data() - Invalid Type value.");
-      return ByteVector::null;
+      return ByteVector();
     }
   }
 }
index 1a66cdd58280c76b89e09a31c71ba11c1117737d..2f02795818e01d83851dee9128dc6e15f819f1c6 100644 (file)
@@ -98,22 +98,22 @@ public:
     CPPUNIT_ASSERT(unsuccessful.contains("A"));
     CPPUNIT_ASSERT(unsuccessful.contains("MP+"));
   }
-  
+
   void testTextBinary()
   {
     APE::Item item = APE::Item("DUMMY", "Test Text");
     CPPUNIT_ASSERT_EQUAL(String("Test Text"), item.toString());
-    CPPUNIT_ASSERT_EQUAL(ByteVector::null, item.binaryData());
-    
+    CPPUNIT_ASSERT_EQUAL(ByteVector(), item.binaryData());
+
     ByteVector data("Test Data");
     item.setBinaryData(data);
     CPPUNIT_ASSERT(item.values().isEmpty());
     CPPUNIT_ASSERT_EQUAL(String::null, item.toString());
     CPPUNIT_ASSERT_EQUAL(data, item.binaryData());
-    
+
     item.setValue("Test Text 2");
     CPPUNIT_ASSERT_EQUAL(String("Test Text 2"), item.toString());
-    CPPUNIT_ASSERT_EQUAL(ByteVector::null, item.binaryData());
+    CPPUNIT_ASSERT_EQUAL(ByteVector(), item.binaryData());
   }
 
 };
index 0ab689216eec1c0b41f1622b48352c344664a06e..b9e31f873954b35e9c4f41536dfadb1fcb0f2a18 100644 (file)
@@ -128,7 +128,7 @@ public:
 
     i.clear();
     CPPUNIT_ASSERT(i.isEmpty());
-    CPPUNIT_ASSERT(!i.isNull());
+    CPPUNIT_ASSERT(!i.isNull()); // deprecated, but worth it to check.
   }
 
   void testFind1()
index b0fec90b15d51fa1bdcdd0a66d8a0d55c9cd99d3..7f6df152bd3fcdb6df10cc61a84920f99d39f165 100644 (file)
@@ -56,7 +56,7 @@ public:
     CPPUNIT_ASSERT_EQUAL(ByteVector("a"), stream.readBlock(1));
     CPPUNIT_ASSERT_EQUAL(ByteVector("bc"), stream.readBlock(2));
     CPPUNIT_ASSERT_EQUAL(ByteVector("d"), stream.readBlock(3));
-    CPPUNIT_ASSERT_EQUAL(ByteVector::null, stream.readBlock(3));
+    CPPUNIT_ASSERT_EQUAL(ByteVector(""), stream.readBlock(3));
   }
 
   void testRemoveBlock()
index 5088841f6718a0755c5724f4ddd440b423094652..036ab2c7c49129ce7870bbec2e6aba0879f83c60 100644 (file)
@@ -38,7 +38,7 @@ class PublicFrame : public ID3v2::Frame
       { return ID3v2::Frame::readStringField(data, encoding, positon); }
     virtual String toString() const { return String::null; }
     virtual void parseFields(const ByteVector &) {}
-    virtual ByteVector renderFields() const { return ByteVector::null; }
+    virtual ByteVector renderFields() const { return ByteVector(); }
 };
 
 class TestID3v2 : public CppUnit::TestFixture