diff options
author | Johannes Schickel | 2014-12-21 15:58:01 +0100 |
---|---|---|
committer | Johannes Schickel | 2014-12-21 15:58:01 +0100 |
commit | 219d4293119989831f0bc0df095617305e0a0e1e (patch) | |
tree | 979a46fc580d65aa12d7e7c7cf27775aaacf3f03 | |
parent | 0f590561bd0fe7238fcfd5fcee0d8a4dc11b9979 (diff) | |
parent | 200b05246c3e90e61fe6d2e21507b0b936d0ff2b (diff) | |
download | scummvm-rg350-219d4293119989831f0bc0df095617305e0a0e1e.tar.gz scummvm-rg350-219d4293119989831f0bc0df095617305e0a0e1e.tar.bz2 scummvm-rg350-219d4293119989831f0bc0df095617305e0a0e1e.zip |
Merge pull request #550 from bgK/timestamp-overflow
AUDIO: Wrap around in the Timestamp constructor
-rw-r--r-- | audio/timestamp.cpp | 6 | ||||
-rw-r--r-- | test/audio/timestamp.h | 13 |
2 files changed, 15 insertions, 4 deletions
diff --git a/audio/timestamp.cpp b/audio/timestamp.cpp index 1ce971631c..63752812e1 100644 --- a/audio/timestamp.cpp +++ b/audio/timestamp.cpp @@ -39,12 +39,10 @@ Timestamp::Timestamp(uint ms, uint fr) { Timestamp::Timestamp(uint s, uint frames, uint fr) { assert(fr > 0); - _secs = s; + _secs = s + (frames / fr); _framerateFactor = 1000 / Common::gcd<uint>(1000, fr); _framerate = fr * _framerateFactor; - _numFrames = frames * _framerateFactor; - - normalize(); + _numFrames = (frames % fr) * _framerateFactor; } Timestamp Timestamp::convertToFramerate(uint newFramerate) const { diff --git a/test/audio/timestamp.h b/test/audio/timestamp.h index ca56e34a4d..ec42a55ec4 100644 --- a/test/audio/timestamp.h +++ b/test/audio/timestamp.h @@ -2,6 +2,8 @@ #include "audio/timestamp.h" +#include <limits.h> + class TimestampTestSuite : public CxxTest::TestSuite { public: @@ -238,4 +240,15 @@ class TimestampTestSuite : public CxxTest::TestSuite TS_ASSERT_EQUALS(c.numberOfFrames(), 11025); TS_ASSERT_EQUALS(c.totalNumberOfFrames(), 33075); } + + void test_no_overflow() { + // The constructor should not overflow and give incoherent values + const Audio::Timestamp a = Audio::Timestamp(0, UINT_MAX, 1000); + + int secs = UINT_MAX / 1000; + int frames = UINT_MAX % 1000; + + TS_ASSERT_EQUALS(a.secs(), secs); + TS_ASSERT_EQUALS(a.numberOfFrames(), frames); + } }; |