Always explicitly check for divide by zero conditions.
authorScott Wheeler <wheeler@kde.org>
Mon, 2 Aug 2004 12:51:14 +0000 (12:51 +0000)
committerScott Wheeler <wheeler@kde.org>
Mon, 2 Aug 2004 12:51:14 +0000 (12:51 +0000)
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@335132 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

flac/flacproperties.cpp
mpc/mpcproperties.cpp
mpeg/mpegproperties.cpp
ogg/flac/oggflacfile.h

index 0a18c337296bcd1b87ef9091a1d21d6aaf346f81..821de3ca4a65de05a2568bf5b70aa2a8b78cac37 100644 (file)
@@ -129,10 +129,11 @@ void FLAC::Properties::read()
   // The last 4 bits are the most significant 4 bits for the 36 bit
   // stream length in samples. (Audio files measured in days)
 
-  uint highLength = (((flags & 0xf) << 28) / d->sampleRate) << 4;
+  uint highLength =d->sampleRate > 0 ? (((flags & 0xf) << 28) / d->sampleRate) << 4 : 0;
   pos += 4;
 
-  d->length = (d->data.mid(pos, 4).toUInt(true)) / d->sampleRate + highLength;
+  d->length = d->sampleRate > 0 ?
+      (d->data.mid(pos, 4).toUInt(true)) / d->sampleRate + highLength : 0;
   pos += 4;
 
   // Uncompressed bitrate:
@@ -141,9 +142,5 @@ void FLAC::Properties::read()
   
   // Real bitrate:
   
-  if(d->length)
-    d->bitrate = ((d->streamLength * 8L) / d->length) / 1000;
-  else
-    d->bitrate = 0;
-  
+  d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
 }
index ef966faacffb8f39f21686f1784b0dfb65c35c2c..2c333edc46672bc9cdaafcba0ec2b78ba441fb2e 100644 (file)
@@ -133,8 +133,8 @@ void MPC::Properties::read()
   }
 
   unsigned int samples = frames * 1152 - 576;
-  d->length = (samples + (d->sampleRate / 2)) / d->sampleRate;
+  d->length = d->sampleRate > 0 ? (samples + (d->sampleRate / 2)) / d->sampleRate : 0;
 
   if(!d->bitrate)
-    d->bitrate = ((d->streamLength * 8L) / d->length) / 1000;
+    d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
 }
index ab65f0ffa1f2e50ea0b9e37cd7843e15600566bc..ba245b20612ae1860e316806aa0856bf4f70fba1 100644 (file)
@@ -190,9 +190,9 @@ void MPEG::Properties::read()
       static const int blockSize[] = { 0, 384, 1152, 1152 };
 
       double timePerFrame = blockSize[firstHeader.layer()];
-      timePerFrame = timePerFrame / firstHeader.sampleRate();
+      timePerFrame = firstHeader.sampleRate() > 0 ? timePerFrame / firstHeader.sampleRate() : 0;
       d->length = int(timePerFrame * xingHeader.totalFrames());
-      d->bitrate = d->length == 0 ? 0 : xingHeader.totalSize() * 8 / d->length / 1000;
+      d->bitrate = d->length > 0 ? xingHeader.totalSize() * 8 / d->length / 1000 : 0;
   }
 
   // Since there was no valid Xing header found, we hope that we're in a constant
index 4c6e92d51d16adf1a18414d4058e98a0823edbe9..94ec5750936938eb0188f3d0fcb7160a93530003 100644 (file)
@@ -55,7 +55,7 @@ namespace TagLib {
      * information specific to Ogg FLAC files.
      */
 
-    class File : public TagLib::Ogg::File
+    class File : public Ogg::File
     {
     public:
       /*!