From: Benjamin Meyer Date: Sun, 19 Dec 2004 05:45:33 +0000 (+0000) Subject: startsWith() should be used to avoid bugs like: s.mid(0, 4) == "Foo". X-Git-Tag: v1.5~297 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c9f7ec7d6e4a37c1f041a9e4dc2af4cc7198a5a;p=taglib startsWith() should be used to avoid bugs like: s.mid(0, 4) == "Foo". git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@371832 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- diff --git a/mpc/mpcproperties.cpp b/mpc/mpcproperties.cpp index fb61b244..029de5b7 100644 --- a/mpc/mpcproperties.cpp +++ b/mpc/mpcproperties.cpp @@ -106,7 +106,7 @@ static const unsigned short sftable [4] = { 44100, 48000, 37800, 32000 }; void MPC::Properties::read() { - if(d->data.mid(0, 3) != "MP+") + if(!d->data.startsWith("MP+")) return; d->version = d->data[3] & 15; diff --git a/mpeg/id3v1/id3v1tag.cpp b/mpeg/id3v1/id3v1tag.cpp index 624f56b8..b8777b90 100644 --- a/mpeg/id3v1/id3v1tag.cpp +++ b/mpeg/id3v1/id3v1tag.cpp @@ -196,7 +196,7 @@ void ID3v1::Tag::read() ByteVector data = d->file->readBlock(128); // some initial sanity checking - if(data.size() == 128 && data.mid(0, 3) == "TAG") + if(data.size() == 128 && data.startsWith("TAG")) parse(data); else debug("ID3v1 tag is not valid or could not be read at the specified offset."); diff --git a/mpeg/xingheader.cpp b/mpeg/xingheader.cpp index 5a093635..bd251dbb 100644 --- a/mpeg/xingheader.cpp +++ b/mpeg/xingheader.cpp @@ -88,7 +88,7 @@ void MPEG::XingHeader::parse(const ByteVector &data) { // Check to see if a valid Xing header is available. - if(data.mid(0, 4) != "Xing") + if(!data.startsWith("Xing")) return; // If the XingHeader doesn't contain the number of frames and the total stream diff --git a/ogg/oggpageheader.cpp b/ogg/oggpageheader.cpp index 40fe92dc..7da708a8 100644 --- a/ogg/oggpageheader.cpp +++ b/ogg/oggpageheader.cpp @@ -238,7 +238,7 @@ void Ogg::PageHeader::read() // Sanity check -- make sure that we were in fact able to read as much data as // we asked for and that the page begins with "OggS". - if(data.size() != 27 || data.mid(0, 4) != "OggS") { + if(data.size() != 27 || !data.startsWith("OggS")) { debug("Ogg::PageHeader::read() -- error reading page header"); return; }