Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#13531 closed Patch - Bug Fix (fixed)

Fix for Coverity 1456162 and 1456180

Reported by: Gary Buhrmaster Owned by: David Hampton
Priority: minor Milestone: 31.0
Component: MythTV - General Version: Master Head
Severity: medium Keywords:
Cc: Ticket locked: no

Description

Low hanging fruit from Coverity scan.

Sizeof returns size of the array (24 for a 3 array double on some architectures) and not the number of elements.

Compile tested only.

diff --git a/mythtv/libs/libmythui/DisplayResScreen.cpp b/mythtv/libs/libmythui/DisplayResScreen.cpp
index 44ffc8c015..a94fd319c5 100644
--- a/mythtv/libs/libmythui/DisplayResScreen.cpp
+++ b/mythtv/libs/libmythui/DisplayResScreen.cpp
@@ -140,7 +140,7 @@ int DisplayResScreen::FindBestMatch(const DisplayResVector& dsr,
                 while (!end)
                 {
                     double precisions1[] = {0.001, 0.01, 0.1};
-                    for (uint p = 0; p < sizeof(precisions1); p++)
+                    for (uint p = 0; p < (sizeof(precisions1)/sizeof(precisions1[0])); p++)
                     {
                         double precision = precisions1[p];
                         for (size_t j=0; j < rates.size(); ++j)
@@ -159,7 +159,7 @@ int DisplayResScreen::FindBestMatch(const DisplayResVector& dsr,
                     // Can't find exact frame rate, so try rounding to the
                     // nearest integer, so 23.97Hz will work with 24Hz etc
                     double precisions2[] = {0.01, 0.1, 1};
-                    for (uint p = 0; p < sizeof(precisions2); p++)
+                    for (uint p = 0; p < (sizeof(precisions2)/sizeof(precisions2[0])); p++)
                     {
                         double precision = precisions2[p];
                         double rounded = round(videorate);

Change History (5)

comment:1 Changed 5 years ago by jpilk

This looks a likely cure for my recent a/v sync issue. Patching in my build system has been awkward and error prone. I'm sure git does it better but I haven't yet found how...

comment:2 Changed 5 years ago by David Hampton

Owner: set to David Hampton
Status: newassigned

comment:3 Changed 5 years ago by David Hampton

Milestone: needs_triage31.0

comment:4 Changed 5 years ago by David Hampton <mythtv@…>

Resolution: fixed
Status: assignedclosed

In 078eeaf362/mythtv:

Use a range-based for loop to step through precision.

This fixes a newly introduced bug in computing the length of array,
that was created when switching the loop variable from a double to an
int. Fixes #13531.

comment:5 Changed 5 years ago by jpilk

This 'fix' may be more syntactically correct but I'm still losing a/v sync in continuous playback on a no-nVidia ffmpeg-decode box. The logs do not reflect this. May be time for a new ticket.

Note: See TracTickets for help on using tickets.