[mythtv-commits] Ticket #11536: Fix hard-coded string lengths
MythTV
noreply at mythtv.org
Sun May 12 13:55:28 UTC 2013
#11536: Fix hard-coded string lengths
----------------------------------+-------------------------
Reporter: stichnot | Owner:
Type: Developer Task | Status: new
Priority: minor | Milestone: 0.27
Component: MythTV - General | Version: Master Head
Severity: medium | Keywords:
Ticket locked: 0 |
----------------------------------+-------------------------
The code base has many fragile string comparisons like:
{{{
if (me->Message().left(23) == "MASTER_UPDATE_PROG_INFO")
}}}
The attached patch applies the following transformations, where N is a
numeric constant and c is a string:
{{{
(s.left(N) == c) ==> (s.startsWith(c))
(s.left(N) != c) ==> (!s.startsWith(c))
(s.right(N) == c) ==> (s.endsWith(c))
(s.right(N) != c) ==> (!s.endsWith(c))
(s.left(N).toLower() == c) ==> (s.startsWith(c, Qt::CaseInsensitive))
(s.left(N).toLower() != c) ==> (!s.startsWith(c, Qt::CaseInsensitive))
(s.right(N).toLower() == c) ==> (s.startsWith(c, Qt::CaseInsensitive))
(s.right(N).toLower() != c) ==> (!s.startsWith(c, Qt::CaseInsensitive))
}}}
Through manual inspection and lots of counting on my fingers, I found two
errors in the code. In CC608Decoder::GetXDS():
{{{
else if (key.left(11) == "has_future_rating_")
}}}
and in HttpConfig::ProcessRequest():
{{{
if (request->m_sBaseUrl.right(7) == "config"
}}}
The latter was already noted in a FIXME comment.
--
Ticket URL: <http://code.mythtv.org/trac/ticket/11536>
MythTV <http://code.mythtv.org/trac>
MythTV Media Center
More information about the mythtv-commits
mailing list