libbacktrace: add casts to avoid undefined shifts (78af4ff, 0034e33)

This commit is contained in:
Bartosz Taudul
2026-03-30 19:37:24 +02:00
parent d79b7d4176
commit 52607f70fe

View File

@@ -1165,7 +1165,10 @@ elf_fetch_bits (const unsigned char **ppin, const unsigned char *pinend,
next = __builtin_bswap32 (next);
#endif
#else
next = pin[0] | (pin[1] << 8) | (pin[2] << 16) | (pin[3] << 24);
next = ((uint32_t)pin[0]
| ((uint32_t)pin[1] << 8)
| ((uint32_t)pin[2] << 16)
| ((uint32_t)pin[3] << 24));
#endif
val |= (uint64_t)next << bits;
@@ -1216,7 +1219,10 @@ elf_fetch_bits_backward (const unsigned char **ppin,
next = __builtin_bswap32 (next);
#endif
#else
next = pin[0] | (pin[1] << 8) | (pin[2] << 16) | (pin[3] << 24);
next = ((uint32_t)pin[0]
| ((uint32_t)pin[1] << 8)
| ((uint32_t)pin[2] << 16)
| ((uint32_t)pin[3] << 24));
#endif
val <<= 32;
@@ -5890,10 +5896,10 @@ elf_uncompress_lzma_block (const unsigned char *compressed,
/* The byte at compressed[off] is ignored for some
reason. */
code = ((compressed[off + 1] << 24)
+ (compressed[off + 2] << 16)
+ (compressed[off + 3] << 8)
+ compressed[off + 4]);
code = (((uint32_t)compressed[off + 1] << 24)
+ ((uint32_t)compressed[off + 2] << 16)
+ ((uint32_t)compressed[off + 3] << 8)
+ (uint32_t)compressed[off + 4]);
off += 5;
/* This is the main LZMA decode loop. */
@@ -6354,10 +6360,10 @@ elf_uncompress_lzma (struct backtrace_state *state,
/* Before that is the size of the index field, which precedes the
footer. */
index_size = (compressed[offset - 4]
| (compressed[offset - 3] << 8)
| (compressed[offset - 2] << 16)
| (compressed[offset - 1] << 24));
index_size = ((size_t)compressed[offset - 4]
| ((size_t)compressed[offset - 3] << 8)
| ((size_t)compressed[offset - 2] << 16)
| ((size_t)compressed[offset - 1] << 24));
index_size = (index_size + 1) * 4;
offset -= 4;