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

This commit is contained in:
Daniel Holbert 2014-10-27 23:17:54 -07:00
parent 931551c3eb
commit a01932fc4c

View File

@ -10,6 +10,8 @@
#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"
@ -106,7 +108,12 @@ EncodeBase64Web(vector<uint8_t> aBinary, string& aEncoded)
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;