Merge pull request #148 from pitrou:ubsan-ptr-add-overflow

PiperOrigin-RevId: 463090354
This commit is contained in:
Victor Costan 2022-07-27 15:28:16 +00:00
commit af720f9a3b
1 changed files with 2 additions and 1 deletions

View File

@ -340,7 +340,8 @@ static inline bool Copy64BytesWithPatternExtension(char* dst, size_t offset) {
if (SNAPPY_PREDICT_TRUE(offset < 16)) { if (SNAPPY_PREDICT_TRUE(offset < 16)) {
if (SNAPPY_PREDICT_FALSE(offset == 0)) return false; if (SNAPPY_PREDICT_FALSE(offset == 0)) return false;
// Extend the pattern to the first 16 bytes. // Extend the pattern to the first 16 bytes.
for (int i = 0; i < 16; i++) dst[i] = dst[i - offset]; // The simpler formulation of `dst[i - offset]` induces undefined behavior.
for (int i = 0; i < 16; i++) dst[i] = (dst - offset)[i];
// Find a multiple of pattern >= 16. // Find a multiple of pattern >= 16.
static std::array<uint8_t, 16> pattern_sizes = []() { static std::array<uint8_t, 16> pattern_sizes = []() {
std::array<uint8_t, 16> res; std::array<uint8_t, 16> res;