Modify
Warning Please read the Ticket HowTo before creating or commenting on a ticket. Failure to do so may cause your ticket to be rejected or result in a slower response.

Opened 12 months ago

Closed 12 months 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

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 stichnot 12 months ago.

Download all attachments as: .zip

Change History (3)

Changed 12 months ago by stichnot

comment:1 Changed 12 months ago by stichnot

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

comment:2 Changed 12 months 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

Action
as closed .
The resolution will be deleted. Next status will be 'new'.
Author


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

 
Note: See TracTickets for help on using tickets.