On Wed, 16 Aug 2023 12:33:47 GMT, Coleen Phillimore <cole...@openjdk.org> wrote:
>> When we read the 64 bit values in the code, the values are 64 bits though. >> So static_cast<> to narrow the result is more correct ? > > This code: > > uint64_t isa; > if (!_reader.read_uleb128(&isa, 4)) { > // isa register is 4 bytes wide. > return false; > } > _state->_isa = isa; // only save 4 bytes > > returns 64 bit of information into isa from this read_uleb128 call, even > though it passes 4. I've quickly skimmed through the usages of `read_uleb128`. We only seem to be reading either directly into a proper `uint64_t` or we are reading 4 bytes (i.e. `check_size = 4`). In the latter case, we could either: - add a `static_cast` for the read value when storing it into a 32 bit field, as for example for `isa` above (i.e. `_state->_isa = static_cast<uint32_t>(isa)`). - provide a 32 bit `read_uleb128()` version that hides the casting. I guess it's fine to just go with a `static_cast` when storing to a field for the few cases we have. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/15233#discussion_r1295863147