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 18:12:10 -07:00
Родитель c1bc87650e
Коммит 1b6621fefd
1 изменённых файлов: 8 добавлений и 1 удалений

Просмотреть файл

@ -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]];
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;