Skip to content

Commit

Permalink
Make substring comparisons less fragile. Fixes #11536.
Browse files Browse the repository at this point in the history
  • Loading branch information
stichnot committed May 13, 2013
1 parent 892cd64 commit 38608a4
Show file tree
Hide file tree
Showing 57 changed files with 238 additions and 234 deletions.
14 changes: 7 additions & 7 deletions mythtv/libs/libmyth/programinfo.cpp
Expand Up @@ -866,8 +866,8 @@ ProgramInfo::ProgramInfo(const QString &_pathname,

QString pn = _pathname;
if ((!_pathname.startsWith("myth://")) &&
(_pathname.right(4).toLower() == ".iso" ||
_pathname.right(4).toLower() == ".img" ||
(_pathname.endsWith(".iso", Qt::CaseInsensitive) ||
_pathname.endsWith(".img", Qt::CaseInsensitive) ||
QDir(_pathname + "/VIDEO_TS").exists()))
{
pn = QString("dvd:%1").arg(_pathname);
Expand Down Expand Up @@ -1676,7 +1676,7 @@ void ProgramInfo::ToMap(InfoMap &progMap,
progMap["yearstars"] = "";

if (!originalAirDate.isValid() ||
(!programid.isEmpty() && (programid.left(2) == "MV")))
(!programid.isEmpty() && programid.startsWith("MV")))
{
progMap["originalairdate"] = "";
progMap["shortoriginalairdate"] = "";
Expand Down Expand Up @@ -2176,13 +2176,13 @@ static ProgramInfoType discover_program_info_type(
if (fn_lower.startsWith("dvd:") ||
fn_lower.endsWith(".iso") ||
fn_lower.endsWith(".img") ||
((pathname.left(1) == "/") &&
((pathname.startsWith("/")) &&
QDir(pathname + "/VIDEO_TS").exists()))
{
pit = kProgramInfoTypeVideoDVD;
}
else if (fn_lower.startsWith("bd:") ||
((pathname.left(1) == "/") &&
((pathname.startsWith("/")) &&
QDir(pathname + "/BDMV").exists()))
{
pit = kProgramInfoTypeVideoBD;
Expand Down Expand Up @@ -4107,7 +4107,7 @@ QString ProgramInfo::DiscoverRecordingDirectory(void) const
return "";

QString path = GetPlaybackURL(false, true);
if (path.left(1) == "/")
if (path.startsWith("/"))
{
QFileInfo testFile(path);
return testFile.path();
Expand Down Expand Up @@ -4508,7 +4508,7 @@ QString ProgramInfo::i18n(const QString &msg)
void ProgramInfo::SubstituteMatches(QString &str)
{
QString pburl = GetPlaybackURL(false, true);
if (pburl.left(7) == "myth://")
if (pburl.startsWith("myth://"))
{
str.replace(QString("%DIR%"), pburl);
}
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmyth/programinfo.h
Expand Up @@ -320,12 +320,12 @@ class MPUBLIC ProgramInfo
{ return GetProgramInfoType() == kProgramInfoTypeVideoDVD; }
bool IsVideoBD(void) const
{ return GetProgramInfoType() == kProgramInfoTypeVideoBD; }
bool IsLocal(void) const { return pathname.left(1) == "/"
bool IsLocal(void) const { return pathname.startsWith("/")
#ifdef _WIN32
|| pathname.at(1) == ':'
#endif
; }
bool IsMythStream(void) const { return pathname.left(7) == "myth://"; }
bool IsMythStream(void) const { return pathname.startsWith("myth://"); }
bool IsPathSet(void) const { return GetBasename() != pathname; }
bool HasPathname(void) const { return !GetPathname().isEmpty(); }
bool IsFileReadable(void) const;
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmyth/schemawizard.cpp
Expand Up @@ -425,12 +425,12 @@ SchemaUpgradeWizard::PromptForUpgrade(const char *name,
if (m_expertMode)
{
resp = getResponse("Would you like to use the existing schema?", "yes");
if (resp.isEmpty() || resp.left(1).toLower() == "y")
if (resp.isEmpty() || resp.startsWith("y", Qt::CaseInsensitive))
return MYTH_SCHEMA_USE_EXISTING;
}

resp = getResponse("\nShall I upgrade this database?", "yes");
if (!resp.isEmpty() && resp.left(1).toLower() != "y")
if (!resp.isEmpty() && !resp.startsWith("y", Qt::CaseInsensitive))
return MYTH_SCHEMA_EXIT;

if (connections)
Expand All @@ -441,7 +441,7 @@ SchemaUpgradeWizard::PromptForUpgrade(const char *name,
{
resp = getResponse("\nA database backup might be a good idea"
"\nAre you sure you want to upgrade?", "no");
if (resp.isEmpty() || resp.left(1).toLower() == "n")
if (resp.isEmpty() || resp.startsWith("n", Qt::CaseInsensitive))
return MYTH_SCHEMA_EXIT;
}

Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmyth/settings.h
Expand Up @@ -441,8 +441,8 @@ class MPUBLIC BooleanSetting : public Setting
virtual void setValue(const QString &newValue)
{
setValue((newValue=="1" ||
newValue.toLower().left(1)=="y" ||
newValue.toLower().left(1)=="t"));
newValue.toLower().startsWith("y") ||
newValue.toLower().startsWith("t")));
}

signals:
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmyth/storagegroupeditor.cpp
Expand Up @@ -96,7 +96,7 @@ void StorageGroupEditor::open(QString name)
if (name.isEmpty())
return;

if (name.right(1) != "/")
if (!name.endsWith("/"))
name.append("/");

MSqlQuery query(MSqlQuery::InitCon());
Expand All @@ -118,7 +118,7 @@ void StorageGroupEditor::open(QString name)
if (result == SGPopup_CANCEL)
return;

if (name.right(1) != "/")
if (!name.endsWith("/"))
name.append("/");

MSqlQuery query(MSqlQuery::InitCon());
Expand Down Expand Up @@ -257,7 +257,7 @@ void StorageGroupListEditor::open(QString name)
{
lastValue = name;

if (name.left(28) == "__CREATE_NEW_STORAGE_GROUP__")
if (name.startsWith("__CREATE_NEW_STORAGE_GROUP__"))
{
if (name.length() > 28)
{
Expand Down Expand Up @@ -286,7 +286,7 @@ void StorageGroupListEditor::open(QString name)
void StorageGroupListEditor::doDelete(void)
{
QString name = listbox->getValue();
if (name.left(28) == "__CREATE_NEW_STORAGE_GROUP__")
if (name.startsWith("__CREATE_NEW_STORAGE_GROUP__"))
return;

bool is_master_host = gCoreContext->IsMasterHost();
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/logging.cpp
Expand Up @@ -1120,7 +1120,7 @@ int verboseArgParse(QString arg)
option = (*it).toLower();
bool reverseOption = false;

if (option != "none" && option.left(2) == "no")
if (option != "none" && option.startsWith("no"))
{
reverseOption = true;
option = option.right(option.length() - 2);
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythmiscutil.cpp
Expand Up @@ -959,7 +959,7 @@ void wrapList(QStringList &list, int width)
QString left = string.left(width);
bool inserted = false;

while( !inserted && left.right(1) != " " )
while( !inserted && !left.endsWith(" " ))
{
if( string.mid(left.size(), 1) == " " )
{
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/plist.cpp
Expand Up @@ -233,7 +233,7 @@ void PList::ParseBinaryPList(const QByteArray &data)
.arg(size).arg(data.left(8).data()));

// check plist type & version
if ((data.left(6) != MAGIC) ||
if ((!data.startsWith(MAGIC)) ||
(data.mid(MAGIC_SIZE, VERSION_SIZE) != VERSION))
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Unrecognised start sequence. Corrupt?");
Expand Down
16 changes: 8 additions & 8 deletions mythtv/libs/libmythbase/remotefile.cpp
Expand Up @@ -268,10 +268,10 @@ bool RemoteFile::DeleteFile(const QString &url)
QString filename = qurl.path();
QString sgroup = qurl.userName();

if (!qurl.fragment().isEmpty() || url.right(1) == "#")
if (!qurl.fragment().isEmpty() || url.endsWith("#"))
filename = filename + "#" + qurl.fragment();

if (filename.left(1) == "/")
if (filename.startsWith("/"))
filename = filename.right(filename.length()-1);

if (filename.isEmpty() || sgroup.isEmpty())
Expand Down Expand Up @@ -301,10 +301,10 @@ bool RemoteFile::Exists(const QString &url, struct stat *fileinfo)
QString filename = qurl.path();
QString sgroup = qurl.userName();

if (!qurl.fragment().isEmpty() || url.right(1) == "#")
if (!qurl.fragment().isEmpty() || url.endsWith("#"))
filename = filename + "#" + qurl.fragment();

if (filename.left(1) == "/")
if (filename.startsWith("/"))
filename = filename.right(filename.length()-1);

if (filename.isEmpty())
Expand Down Expand Up @@ -356,10 +356,10 @@ QString RemoteFile::GetFileHash(const QString &url)
QString hostname = qurl.host();
QString sgroup = qurl.userName();

if (!qurl.fragment().isEmpty() || url.right(1) == "#")
if (!qurl.fragment().isEmpty() || url.endsWith("#"))
filename = filename + "#" + qurl.fragment();

if (filename.left(1) == "/")
if (filename.startsWith("/"))
filename = filename.right(filename.length()-1);

if (filename.isEmpty() || sgroup.isEmpty())
Expand Down Expand Up @@ -651,10 +651,10 @@ QDateTime RemoteFile::LastModified(const QString &url)
QString filename = qurl.path();
QString sgroup = qurl.userName();

if (!qurl.fragment().isEmpty() || url.right(1) == "#")
if (!qurl.fragment().isEmpty() || url.endsWith("#"))
filename = filename + "#" + qurl.fragment();

if (filename.left(1) == "/")
if (filename.startsWith("/"))
filename = filename.right(filename.length()-1);

if (filename.isEmpty() || sgroup.isEmpty())
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/storagegroup.cpp
Expand Up @@ -549,7 +549,7 @@ bool StorageGroup::FindDirs(const QString group, const QString hostname,
.toByteArray().constData());
dirname.replace(QRegExp("^\\s*"), "");
dirname.replace(QRegExp("\\s*$"), "");
if (dirname.right(1) == "/")
if (dirname.endsWith("/"))
dirname.remove(dirname.length() - 1, 1);

if (dirlist)
Expand Down
Expand Up @@ -90,14 +90,14 @@ QString FileServerHandler::LocalFilePath(const QUrl &url,
lpath = lpath.section('/', -1);

QString fpath = lpath;
if (fpath.right(4) == ".png")
if (fpath.endsWith(".png"))
fpath = fpath.left(fpath.length() - 4);

ProgramInfo pginfo(fpath);
if (pginfo.GetChanID())
{
QString pburl = GetPlaybackURL(&pginfo);
if (pburl.left(1) == "/")
if (pburl.startsWith("/"))
{
lpath = pburl.section('/', 0, -2) + "/" + lpath;
LOG(VB_FILE, LOG_INFO,
Expand Down Expand Up @@ -517,7 +517,7 @@ QList<FileSystemInfo> FileServerHandler::QueryFileSystems(void)
.toByteArray().constData());
disk.setPath(currentDir);

if (currentDir.right(1) == "/")
if (currentDir.endsWith("/"))
currentDir.remove(currentDir.length() - 1, 1);

checkDir.setPath(currentDir);
Expand Down
Expand Up @@ -58,7 +58,7 @@ QString GetPlaybackURL(ProgramInfo *pginfo, bool storePath)
else
{
result = pginfo->GetPlaybackURL(false, true);
if (storePath && result.left(1) == "/")
if (storePath && result.startsWith("/"))
recordingPathCache[cacheKey] = result;
}

Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/DVD/dvdringbuffer.cpp
Expand Up @@ -38,11 +38,11 @@ DVDInfo::DVDInfo(const QString &filename)
{
LOG(VB_PLAYBACK, LOG_INFO, QString("DVDInfo: Trying %1").arg(filename));
QString name = filename;
if (name.left(6) == "dvd://")
if (name.startsWith("dvd://"))
name.remove(0,5);
else if (name.left(5) == "dvd:/")
else if (name.startsWith("dvd:/"))
name.remove(0,4);
else if (name.left(4) == "dvd:")
else if (name.startsWith("dvd:"))
name.remove(0,4);

QByteArray fname = name.toLocal8Bit();
Expand Down
10 changes: 5 additions & 5 deletions mythtv/libs/libmythtv/cc608decoder.cpp
Expand Up @@ -376,7 +376,7 @@ void CC608Decoder::FormatCCField(int tc, int field, int data)
len = NewRowCC(mode, len);

if (len == 0 ||
ccbuf[mode].left(1) == "\b")
ccbuf[mode].startsWith("\b"))
{
ccbuf[mode] += (char)'\b';
len++;
Expand Down Expand Up @@ -1122,16 +1122,16 @@ QString CC608Decoder::GetXDS(const QString &key) const

if (key == "ratings")
return QString::number(GetRatingSystems(false));
else if (key.left(11) == "has_rating_")
else if (key.startsWith("has_rating_"))
return ((1<<key.right(1).toUInt()) & GetRatingSystems(false))?"1":"0";
else if (key.left(7) == "rating_")
else if (key.startsWith("rating_"))
return GetRatingString(key.right(1).toUInt(), false);

else if (key == "future_ratings")
return QString::number(GetRatingSystems(true));
else if (key.left(11) == "has_future_rating_")
else if (key.startsWith("has_future_rating_"))
return ((1<<key.right(1).toUInt()) & GetRatingSystems(true))?"1":"0";
else if (key.left(14) == "future_rating_")
else if (key.startsWith("future_rating_"))
return GetRatingString(key.right(1).toUInt(), true);

else if (key == "programname")
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/channelscan/channelscanner.cpp
Expand Up @@ -140,7 +140,7 @@ void ChannelScanner::Scan(

// HACK HACK HACK -- begin
// if using QAM we may need additional time... (at least with HD-3000)
if ((mod.left(3).toLower() == "qam") &&
if ((mod.startsWith("qam", Qt::CaseInsensitive)) &&
(sigmonScanner->GetSignalTimeout() < 1000))
{
sigmonScanner->SetSignalTimeout(1000);
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/channelscan/iptvchannelfetcher.cpp
Expand Up @@ -210,7 +210,7 @@ void IPTVChannelFetcher::SetMessage(const QString &status)
QString IPTVChannelFetcher::DownloadPlaylist(const QString &url,
bool inQtThread)
{
if (url.left(4).toLower() == "file")
if (url.startsWith("file", Qt::CaseInsensitive))
{
QString ret = "";
QUrl qurl(url);
Expand Down
18 changes: 9 additions & 9 deletions mythtv/libs/libmythtv/decoderbase.cpp
Expand Up @@ -1145,23 +1145,23 @@ int to_track_type(const QString &str)
{
int ret = -1;

if (str.left(5) == "AUDIO")
if (str.startsWith("AUDIO"))
ret = kTrackTypeAudio;
else if (str.left(5) == "VIDEO")
else if (str.startsWith("VIDEO"))
ret = kTrackTypeVideo;
else if (str.left(8) == "SUBTITLE")
else if (str.startsWith("SUBTITLE"))
ret = kTrackTypeSubtitle;
else if (str.left(5) == "CC608")
else if (str.startsWith("CC608"))
ret = kTrackTypeCC608;
else if (str.left(5) == "CC708")
else if (str.startsWith("CC708"))
ret = kTrackTypeCC708;
else if (str.left(3) == "TTC")
else if (str.startsWith("TTC"))
ret = kTrackTypeTeletextCaptions;
else if (str.left(3) == "TTM")
else if (str.startsWith("TTM"))
ret = kTrackTypeTeletextMenu;
else if (str.left(3) == "TFL")
else if (str.startsWith("TFL"))
ret = kTrackTypeTextSubtitle;
else if (str.left(7) == "RAWTEXT")
else if (str.startsWith("RAWTEXT"))
ret = kTrackTypeRawText;
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/fileringbuffer.cpp
Expand Up @@ -200,8 +200,8 @@ bool FileRingBuffer::OpenFile(const QString &lfilename, uint retry_ms)
}

bool is_local =
(filename.left(4) != "/dev") &&
((filename.left(1) == "/") || QFile::exists(filename));
(!filename.startsWith("/dev")) &&
((filename.startsWith("/")) || QFile::exists(filename));

if (is_local)
{
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/jobqueue.cpp
Expand Up @@ -91,7 +91,7 @@ void JobQueue::customEvent(QEvent *e)
MythEvent *me = (MythEvent *)e;
QString message = me->Message();

if (message.left(9) == "LOCAL_JOB")
if (message.startsWith("LOCAL_JOB"))
{
// LOCAL_JOB action ID jobID
// LOCAL_JOB action type chanid recstartts hostname
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/mythplayer.cpp
Expand Up @@ -1046,7 +1046,7 @@ void MythPlayer::InitFilters(void)
}
else
{
if ((filters.length() > 1) && (filters.right(1) != ","))
if ((filters.length() > 1) && (!filters.endsWith(",")))
filters += ",";
filters += videoFiltersForProgram.mid(1);
}
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/playercontext.cpp
Expand Up @@ -747,7 +747,7 @@ QString PlayerContext::GetFilters(const QString &baseFilters) const
}
else
{
if (!filters.isEmpty() && (filters.right(1) != ","))
if (!filters.isEmpty() && (!filters.endsWith(",")))
filters += ",";

filters += chanFilters.mid(1);
Expand Down

0 comments on commit 38608a4

Please sign in to comment.