Opened 5 years ago

Closed 5 years ago

#11536 closed Developer Task (fixed)

Fix hard-coded string lengths

Reported by: stichnot Owned by: stichnot
Priority: minor Milestone: 0.27
Component: MythTV - General Version: Master Head
Severity: medium Keywords:
Cc: Ticket locked: no


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 stichnot 5 years ago.

Download all attachments as: .zip

Change History (3)

Changed 5 years ago by stichnot

comment:1 Changed 5 years ago by stichnot

  • Owner set to stichnot
  • Status changed from new to accepted

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

  • Resolution set to fixed
  • Status changed from accepted to closed

In 38608a4b587235e3dd907c7b2b5c1a0de6815ba6/mythtv:

Make substring comparisons less fragile. Fixes #11536.

Add Comment

Modify Ticket

as closed The owner will remain stichnot.
The resolution will be deleted. Next status will be 'new'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.