|
1 | 1 | //! Main evaluator loop and setting up the initial stack frame.
|
2 | 2 |
|
3 | 3 | use std::ffi::OsStr;
|
| 4 | +use std::convert::TryFrom; |
4 | 5 |
|
5 | 6 | use rand::rngs::StdRng;
|
6 | 7 | use rand::SeedableRng;
|
@@ -101,25 +102,25 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
|
101 | 102 | // First argument: pointer to `main()`.
|
102 | 103 | let main_ptr = ecx.memory.create_fn_alloc(FnVal::Instance(main_instance));
|
103 | 104 | // Second argument (argc): length of `config.args`.
|
104 |
| - let argc = Scalar::from_uint(config.args.len() as u128, ecx.pointer_size()); |
| 105 | + let argc = Scalar::from_uint(u64::try_from(config.args.len()).unwrap(), ecx.pointer_size()); |
105 | 106 | // Third argument (`argv`): created from `config.args`.
|
106 | 107 | let argv = {
|
107 | 108 | // Put each argument in memory, collect pointers.
|
108 | 109 | let mut argvs = Vec::<Scalar<Tag>>::new();
|
109 | 110 | for arg in config.args.iter() {
|
110 | 111 | // Make space for `0` terminator.
|
111 |
| - let size = arg.len() as u64 + 1; |
| 112 | + let size = u64::try_from(arg.len()).unwrap().checked_add(1).unwrap(); |
112 | 113 | let arg_type = tcx.mk_array(tcx.types.u8, size);
|
113 | 114 | let arg_place = ecx.allocate(ecx.layout_of(arg_type)?, MiriMemoryKind::Machine.into());
|
114 | 115 | ecx.write_os_str_to_c_str(OsStr::new(arg), arg_place.ptr, size)?;
|
115 | 116 | argvs.push(arg_place.ptr);
|
116 | 117 | }
|
117 | 118 | // Make an array with all these pointers, in the Miri memory.
|
118 | 119 | let argvs_layout =
|
119 |
| - ecx.layout_of(tcx.mk_array(tcx.mk_imm_ptr(tcx.types.u8), argvs.len() as u64))?; |
| 120 | + ecx.layout_of(tcx.mk_array(tcx.mk_imm_ptr(tcx.types.u8), u64::try_from(argvs.len()).unwrap()))?; |
120 | 121 | let argvs_place = ecx.allocate(argvs_layout, MiriMemoryKind::Machine.into());
|
121 | 122 | for (idx, arg) in argvs.into_iter().enumerate() {
|
122 |
| - let place = ecx.mplace_field(argvs_place, idx as u64)?; |
| 123 | + let place = ecx.mplace_field(argvs_place, u64::try_from(idx).unwrap())?; |
123 | 124 | ecx.write_scalar(arg, place.into())?;
|
124 | 125 | }
|
125 | 126 | ecx.memory.mark_immutable(argvs_place.ptr.assert_ptr().alloc_id)?;
|
@@ -153,13 +154,13 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
|
153 | 154 | cmd.push(std::char::from_u32(0).unwrap());
|
154 | 155 |
|
155 | 156 | let cmd_utf16: Vec<u16> = cmd.encode_utf16().collect();
|
156 |
| - let cmd_type = tcx.mk_array(tcx.types.u16, cmd_utf16.len() as u64); |
| 157 | + let cmd_type = tcx.mk_array(tcx.types.u16, u64::try_from(cmd_utf16.len()).unwrap()); |
157 | 158 | let cmd_place = ecx.allocate(ecx.layout_of(cmd_type)?, MiriMemoryKind::Machine.into());
|
158 | 159 | ecx.machine.cmd_line = Some(cmd_place.ptr);
|
159 | 160 | // Store the UTF-16 string. We just allocated so we know the bounds are fine.
|
160 | 161 | let char_size = Size::from_bytes(2);
|
161 | 162 | for (idx, &c) in cmd_utf16.iter().enumerate() {
|
162 |
| - let place = ecx.mplace_field(cmd_place, idx as u64)?; |
| 163 | + let place = ecx.mplace_field(cmd_place, u64::try_from(idx).unwrap())?; |
163 | 164 | ecx.write_scalar(Scalar::from_uint(c, char_size), place.into())?;
|
164 | 165 | }
|
165 | 166 | }
|
|
0 commit comments