Bug 1083373 part 2: Assert that array index is in-bounds, and cast it from char to size_t to fix clang warning. r=edwin
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 27 Oct 2014 23:17:54 -0700
changeset 212594 8d4d7a689070e7b5a292b615107baf297b941ab6
parent 212593 853cd62361614969284eaab48bdc1845d58efd43
child 212595 a9fc09c6af9436b0efa4a73daafd225071fda1fa
push id27721
push usercbook@mozilla.com
push dateTue, 28 Oct 2014 14:55:05 +0000
treeherdermozilla-central@c0ddb1b098ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin
bugs1083373
milestone36.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 1083373 part 2: Assert that array index is in-bounds, and cast it from char to size_t to fix clang warning. r=edwin
media/gmp-clearkey/0.1/ClearKeyUtils.cpp
--- a/media/gmp-clearkey/0.1/ClearKeyUtils.cpp
+++ b/media/gmp-clearkey/0.1/ClearKeyUtils.cpp
@@ -5,16 +5,18 @@
 #include <algorithm>
 #include <assert.h>
 #include <ctype.h>
 #include <stdarg.h>
 #include <stdint.h>
 #include <vector>
 
 #include "ClearKeyUtils.h"
+#include "mozilla/ArrayUtils.h"
+#include "mozilla/Assertions.h"
 #include "mozilla/Endian.h"
 #include "mozilla/NullPtr.h"
 #include "openaes/oaes_lib.h"
 
 using namespace std;
 
 #define FOURCC(a,b,c,d) ((a << 24) + (b << 16) + (c << 8) + d)
 
@@ -101,17 +103,22 @@ EncodeBase64Web(vector<uint8_t> aBinary,
       data++;
     } else {
       out[i] = 0;
     }
 
     out[i] += (*data >> (shift + 2)) & sMask;
     shift = (shift + 2) % 8;
 
-    out[i] = sAlphabet[out[i]];
+    // Cast idx to size_t before using it as an array-index,
+    // to pacify clang 'Wchar-subscripts' warning:
+    size_t idx = static_cast<size_t>(out[i]);
+    MOZ_ASSERT(idx < MOZ_ARRAY_LENGTH(sAlphabet),
+               "out of bounds index for 'sAlphabet'");
+    out[i] = sAlphabet[idx];
   }
 
   return true;
 }
 
 /* static */ void
 ClearKeyUtils::ParseInitData(const uint8_t* aInitData, uint32_t aInitDataSize,
                              vector<KeyId>& aOutKeys)