Fix the same shifting UB for SDAS objects as for RGBDS ones

This commit is contained in:
Rangi committed 2026-07-14 11:13:30 -04:00
1 parent ca2de0f429
commit b13b0c8eb8
2 files changed
+4 -8

No files matched your search

+2 -7
View File
@@ -57,13 +57,8 @@ static int64_t readLong(FILE *file) {
if (byte == EOF) {
return INT64_MAX;
}
// This must be casted to `unsigned`, not `uint8_t`. Rationale:
// the type of the shift is the type of `byte` after undergoing
// integer promotion, which would be `int` if this was casted to
// `uint8_t`, because int is large enough to hold a byte. This
// however causes values larger than 127 to be too large when
// shifted, potentially triggering undefined behavior.
value |= static_cast<unsigned int>(byte) << shift;
// Cast to `uint32_t` to avoid UB when shifting a byte >= 128 by a count >= 24.
value |= static_cast<uint32_t>(byte) << shift;
}
return value;
}