Bug 1533127 - Force unsigned operation. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 08 Mar 2019 03:03:16 +0000
changeset 520961 df1b1891f2f8
parent 520960 22b988a39a32
child 520962 3944dae3dabd
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1533127
milestone67.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 1533127 - Force unsigned operation. r=gerald 1 << 31 is defined since C++14 and produces INT_MIN, but subtracting any positive number from INT_MIN would result in a signed overflow. This can be avoided by making the first argument unsigned (and in this case the second argument will be converted to unsigned as well.) Differential Revision: https://phabricator.services.mozilla.com/D22482
dom/media/BitReader.cpp
--- a/dom/media/BitReader.cpp
+++ b/dom/media/BitReader.cpp
@@ -62,17 +62,18 @@ uint32_t BitReader::ReadUE() {
   if (i == 32) {
     // This can happen if the data is invalid, or if it's
     // short, since ReadBit() will return 0 when it runs
     // off the end of the buffer.
     NS_WARNING("Invalid H.264 data");
     return 0;
   }
   uint32_t r = ReadBits(i);
-  r += (1 << i) - 1;
+  r += (uint32_t(1) << i) - 1;
+
   return r;
 }
 
 // Read signed integer Exp-Golomb-coded.
 int32_t BitReader::ReadSE() {
   int32_t r = ReadUE();
   if (r & 1) {
     return (r + 1) / 2;