Bug 1349658 - Use mozilla::BitwiseCast rather than reinterpret_cast draft
authorCosine <judahiii@gmail.com>
Thu, 31 Aug 2017 03:23:13 -0400
changeset 656424 def7426fd70d4a4abecf95b494dd35893e3bbbd8
parent 656376 5d6e81ba059c5e3082deb2bbd0c22cc4b185d45e
child 656426 8a4533b48243679cd8affd4c690458991bbe9d5a
push id77223
push userbmo:judahiii@gmail.com
push dateThu, 31 Aug 2017 07:28:54 +0000
bugs1349658
milestone57.0a1
Bug 1349658 - Use mozilla::BitwiseCast rather than reinterpret_cast reinterpret_cast would be undefined behavior. MozReview-Commit-ID: KQoEslFlYdM
dom/media/platforms/agnostic/WAVDecoder.cpp
--- a/dom/media/platforms/agnostic/WAVDecoder.cpp
+++ b/dom/media/platforms/agnostic/WAVDecoder.cpp
@@ -2,16 +2,17 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AudioSampleFormat.h"
 #include "WAVDecoder.h"
 #include "mozilla/SyncRunnable.h"
+#include "mozilla/Casting.h"
 #include "VideoUtils.h"
 
 using mp4_demuxer::ByteReader;
 
 namespace mozilla {
 
 int16_t
 DecodeALawSample(uint8_t aValue)
@@ -87,17 +88,17 @@ WaveDataDecoder::ProcessDecode(MediaRawD
   if (!buffer) {
     return DecodePromise::CreateAndReject(
       MediaResult(NS_ERROR_OUT_OF_MEMORY, __func__), __func__);
   }
   for (int i = 0; i < frames; ++i) {
     for (unsigned int j = 0; j < mInfo.mChannels; ++j) {
       if (mInfo.mProfile == 3) {                              //IEEE float Data
         uint32_t v = aReader.ReadU32();
-        float decoded = reinterpret_cast<float&>(v);
+        float decoded = BitwiseCast<float>(v);
         buffer[i * mInfo.mChannels + j] =
             FloatToAudioSample<AudioDataValue>(decoded);
       }
       if (mInfo.mProfile == 6) {                              //ALAW Data
         uint8_t v = aReader.ReadU8();
         int16_t decoded = DecodeALawSample(v);
         buffer[i * mInfo.mChannels + j] =
             IntegerToAudioSample<AudioDataValue>(decoded);