Bug 143938 - timePerFrame incorrectly calculated in mpegproperties.cpp
Summary: timePerFrame incorrectly calculated in mpegproperties.cpp
Status: RESOLVED FIXED
Alias: None
Product: taglib
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Other
: NOR normal
Target Milestone: ---
Assignee: Scott Wheeler
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-07 20:30 UTC by Stephen F. Booth
Modified: 2007-07-18 14:52 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen F. Booth 2007-04-07 20:30:00 UTC
Version:           svn (using KDE Devel)
Installed from:    Compiled sources
Compiler:          gcc version 4.0.1 (Apple Computer, Inc. build 5367) 
OS:                OS X

The calculation of timePerFrame in mepegproperties.cpp almost always results in zero because the result of integer division is being cast to a double.  This leads to the length() method of MPEGFile return 0.  It is necessary to promote one of the ints before dividing to get an accurate result.  Here is a patch with one way to fix the problem:


svn diff mpegproperties.cpp
Index: mpegproperties.cpp
===================================================================
--- mpegproperties.cpp  (revision 651409)
+++ mpegproperties.cpp  (working copy)
@@ -213,7 +213,7 @@
   {
       static const int blockSize[] = { 0, 384, 1152, 1152 };
 
-      double timePerFrame = blockSize[firstHeader.layer()] / firstHeader.sampleRate();
+      double timePerFrame = (double)blockSize[firstHeader.layer()] / firstHeader.sampleRate();
       d->length = int(timePerFrame * d->xingHeader->totalFrames());
       d->bitrate = d->length > 0 ? d->xingHeader->totalSize() * 8 / d->length / 1000 : 0;
   }
Comment 1 Scott Wheeler 2007-07-18 14:52:43 UTC
SVN commit 689510 by wheeler:

Promote the int to a float so that the calcualtion works properly.  Patch from Stephen Booth.

BUG:143938


 M  +1 -1      mpegproperties.cpp  


--- trunk/kdesupport/taglib/taglib/mpeg/mpegproperties.cpp #689509:689510
@@ -213,7 +213,7 @@
   {
       static const int blockSize[] = { 0, 384, 1152, 1152 };
 
-      double timePerFrame = blockSize[firstHeader.layer()] / firstHeader.sampleRate();
+      double timePerFrame = double(blockSize[firstHeader.layer()]) / firstHeader.sampleRate();
       d->length = int(timePerFrame * d->xingHeader->totalFrames());
       d->bitrate = d->length > 0 ? d->xingHeader->totalSize() * 8 / d->length / 1000 : 0;
   }