[Zucchini] Fix undefined shift in GetSleb128.
A left shift resulting in truncation is undefined behavior on signed
int types in C++. It is fine to left shift an unsigned type because
there is no issues with two's complement representation or sign bits.
To get around this we need to perform the shift on the uint type and
recast it to a signed int type.
Bug: 860067
Change-Id: Ibace5aceb17c4435d6d37d5e37a16fa781c7dd99
Reviewed-on: https://chromium-review.googlesource.com/1126169
Reviewed-by: Samuel Huang <huangs@chromium.org>
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572577}
NOKEYCHECK=True
GitOrigin-RevId: d550e67840653dd68f49cdab0e58ca7268359bb9
diff --git a/buffer_source.cc b/buffer_source.cc
index 721588a..d72d329 100644
--- a/buffer_source.cc
+++ b/buffer_source.cc
@@ -80,7 +80,7 @@
for (int shift = 0; shift < shift_lim; shift += 7, ++cur) {
uint32_t b = *cur;
// When |shift == 28|, |(b & 0x7F) << shift| discards the "???" bits.
- value |= static_cast<int32_t>(b & 0x7F) << shift;
+ value |= static_cast<int32_t>(static_cast<uint32_t>(b & 0x7F) << shift);
if (!(b & 0x80)) {
*ret = (shift == 28) ? value : SignExtend(shift + 6, value);
seek(cur + 1);