Opened 12 years ago
Closed 12 years ago
#11536 closed Developer Task (fixed)
Fix hard-coded string lengths
Reported by: | Jim Stichnoth | Owned by: | Jim Stichnoth |
---|---|---|---|
Priority: | minor | Milestone: | 0.27 |
Component: | MythTV - General | Version: | Master Head |
Severity: | medium | Keywords: | |
Cc: | Ticket locked: | no |
Description
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.
Attachments (1)
Change History (3)
Changed 12 years ago by
Attachment: | startsendswith.patch added |
---|
comment:1 Changed 12 years ago by
Owner: | set to Jim Stichnoth |
---|---|
Status: | new → accepted |
comment:2 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
Note: See
TracTickets for help on using
tickets.
In 38608a4b587235e3dd907c7b2b5c1a0de6815ba6/mythtv: