Opened 11 years ago

Closed 11 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)

startsendswith.patch (81.7 KB) - added by Jim Stichnoth 11 years ago.

Download all attachments as: .zip

Change History (3)

Changed 11 years ago by Jim Stichnoth

Attachment: startsendswith.patch added

comment:1 Changed 11 years ago by Jim Stichnoth

Owner: set to Jim Stichnoth
Status: newaccepted

comment:2 Changed 11 years ago by Jim Stichnoth <jstichnoth@…>

Resolution: fixed
Status: acceptedclosed

In 38608a4b587235e3dd907c7b2b5c1a0de6815ba6/mythtv:

Make substring comparisons less fragile. Fixes #11536.

Note: See TracTickets for help on using tickets.