forked from OSchip/llvm-project
Fix UB in compiler-rt base64 implementation
As a follow-up to 1454c27b60
This commit is contained in:
parent
221641be02
commit
292ab49d43
|
@ -161,20 +161,21 @@ std::string Base64(const Unit &U) {
|
|||
|
||||
size_t i = 0, j = 0;
|
||||
for (size_t n = U.size() / 3 * 3; i < n; i += 3, j += 4) {
|
||||
uint32_t x = (U[i] << 16) | (U[i + 1] << 8) | U[i + 2];
|
||||
uint32_t x = ((unsigned char)U[i] << 16) | ((unsigned char)U[i + 1] << 8) |
|
||||
(unsigned char)U[i + 2];
|
||||
Buffer[j + 0] = Table[(x >> 18) & 63];
|
||||
Buffer[j + 1] = Table[(x >> 12) & 63];
|
||||
Buffer[j + 2] = Table[(x >> 6) & 63];
|
||||
Buffer[j + 3] = Table[x & 63];
|
||||
}
|
||||
if (i + 1 == U.size()) {
|
||||
uint32_t x = (U[i] << 16);
|
||||
uint32_t x = ((unsigned char)U[i] << 16);
|
||||
Buffer[j + 0] = Table[(x >> 18) & 63];
|
||||
Buffer[j + 1] = Table[(x >> 12) & 63];
|
||||
Buffer[j + 2] = '=';
|
||||
Buffer[j + 3] = '=';
|
||||
} else if (i + 2 == U.size()) {
|
||||
uint32_t x = (U[i] << 16) | (U[i + 1] << 8);
|
||||
uint32_t x = ((unsigned char)U[i] << 16) | ((unsigned char)U[i + 1] << 8);
|
||||
Buffer[j + 0] = Table[(x >> 18) & 63];
|
||||
Buffer[j + 1] = Table[(x >> 12) & 63];
|
||||
Buffer[j + 2] = Table[(x >> 6) & 63];
|
||||
|
|
Loading…
Reference in New Issue