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
☠☠ backed out by c5b93a000dfb ☠ ☠
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 27 Oct 2014 18:12:10 -0700
changeset 212583 c7e523e3d339410de77475c74a87c12ab53be880
parent 212582 a6e6e78b033874adee6293f306ff3e4fed713b1e
child 212584 2abc300df08c66f5541553437baa35d63bfa1cfe
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]];
+    auto idx = out[i];
+    MOZ_ASSERT(idx >= 0 &&
+               static_cast<size_t>(idx) < MOZ_ARRAY_LENGTH(sAlphabet),
+               "out of bounds index for 'sAlphabet'");
+    // Cast idx to size_t to pacify clang 'Wchar-subscripts' warning:
+    out[i] = sAlphabet[static_cast<size_t>(idx)];
   }
 
   return true;
 }
 
 /* static */ void
 ClearKeyUtils::ParseInitData(const uint8_t* aInitData, uint32_t aInitDataSize,
                              vector<KeyId>& aOutKeys)