]> git.lizzy.rs Git - rust.git/commitdiff
use Size addition instead of checked int addition
authorRalf Jung <post@ralfj.de>
Tue, 24 Mar 2020 09:07:46 +0000 (10:07 +0100)
committerRalf Jung <post@ralfj.de>
Wed, 25 Mar 2020 14:53:52 +0000 (15:53 +0100)
src/librustc/mir/interpret/allocation.rs

index 5440aef6fe6c939b11133d3e6e51372905ffd8d2..cd4c7c71ccd90c5063dea6a4fe54e6d794f4c0cd 100644 (file)
@@ -293,7 +293,7 @@ pub fn read_c_str(
         let offset = usize::try_from(ptr.offset.bytes()).unwrap();
         Ok(match self.bytes[offset..].iter().position(|&c| c == 0) {
             Some(size) => {
-                let size_with_null = Size::from_bytes(size.checked_add(1).unwrap());
+                let size_with_null = Size::add(Size::from_bytes(size), Size::from_bytes(1));
                 // Go through `get_bytes` for checks and AllocationExtra hooks.
                 // We read the null, so we include it in the request, but we want it removed
                 // from the result, so we do subslicing.