bug 1206362 be careful about double -> int conversion r=padenot
authorKarl Tomlinson <karlt+@karlt.net>
Mon, 21 Sep 2015 15:44:10 +1200
changeset 263896 830a804fa9597b74f0ee1cf3a78f4e105e192d2e
parent 263895 190ff979320d6be7de47ba45b5f557010f02f1b0
child 263897 ddd169d6bd65771a6811a3bb223a4a385b101690
push id65464
push userktomlinson@mozilla.com
push dateWed, 23 Sep 2015 03:33:21 +0000
treeherdermozilla-inbound@ddd169d6bd65 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1206362
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1206362 be careful about double -> int conversion r=padenot
dom/media/webaudio/AudioBufferSourceNode.cpp
--- a/dom/media/webaudio/AudioBufferSourceNode.cpp
+++ b/dom/media/webaudio/AudioBufferSourceNode.cpp
@@ -710,18 +710,24 @@ AudioBufferSourceNode::SendOffsetAndDura
   int32_t offsetSamples = std::max(0, NS_lround(mOffset * rate));
 
   // Don't set parameter unnecessarily
   if (offsetSamples > 0) {
     aStream->SetInt32Parameter(BUFFERSTART, offsetSamples);
   }
 
   if (mDuration != std::numeric_limits<double>::min()) {
-    bufferEnd = std::min(bufferEnd,
-                         offsetSamples + NS_lround(mDuration * rate));
+    MOZ_ASSERT(mDuration >= 0.0); // provided by Start()
+    MOZ_ASSERT(rate >= 0.0f); // provided by AudioBuffer::Create()
+    static_assert(std::numeric_limits<double>::digits >=
+                  std::numeric_limits<decltype(bufferEnd)>::digits,
+                  "bufferEnd should be represented exactly by double");
+    // + 0.5 rounds mDuration to nearest sample when assigned to bufferEnd.
+    bufferEnd = std::min<double>(bufferEnd,
+                                 offsetSamples + mDuration * rate + 0.5);
   }
   aStream->SetInt32Parameter(BUFFEREND, bufferEnd);
 
   MarkActive();
 }
 
 void
 AudioBufferSourceNode::Stop(double aWhen, ErrorResult& aRv)