| commit | 22ce639d21a6607f23d0c1893a12550613164a83 | [log] [tgz] |
|---|---|---|
| author | Ryo Hashimoto <[email protected]> | Thu Feb 08 12:11:39 2024 |
| committer | Chromeos LUCI <[email protected]> | Tue Feb 13 03:49:13 2024 |
| tree | ee9f176bc87bfbbd7ff3ef3ac89eddd5e6dc9611 | |
| parent | bd1416be85fc5c317a2e6171be066ed98841e643 [diff] |
Use base::checked_cast to convert uint64_t to size_t Do the same thing as http://crrev.com/c/5213529 BUG=b:324173685 TEST=cros_run_unit_tests --board=hana --packages cbor Change-Id: I22b877d314f6f0af9b67d7fb87211311bcdb5a44 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/cbor/+/5274069 Reviewed-by: Tom Hughes <[email protected]> Commit-Queue: Ryo Hashimoto <[email protected]> Tested-by: Ryo Hashimoto <[email protected]>
diff --git a/reader.cc b/reader.cc index 03c0995..b4a77e1 100644 --- a/reader.cc +++ b/reader.cc
@@ -367,8 +367,14 @@ error_code_ = DecoderError::INCOMPLETE_CBOR_DATA; return std::nullopt; } - const base::span<const uint8_t> ret = rest_.first(num_bytes); - rest_ = rest_.subspan(num_bytes); + + // The `uint64_t` => `size_t` conversion below will always succeed + // because the `if` condition above implies that `num_bytes` fits into a + // `size_t`. + size_t size = base::checked_cast<size_t>(num_bytes); + + const base::span<const uint8_t> ret = rest_.first(size); + rest_ = rest_.subspan(size); return ret; }