@@ -356,19 +356,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
356
356
let len = bytes. len ( ) ;
357
357
// If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required null
358
358
// terminator to memory using the `ptr` pointer would cause an overflow.
359
- if ( len as u64 ) < size {
360
- let this = self . eval_context_mut ( ) ;
361
- let tcx = & { this. tcx . tcx } ;
362
- let buffer = this. memory . get_mut ( ptr. alloc_id ) ?. get_bytes_mut ( tcx, ptr, Size :: from_bytes ( len as u64 + 1 ) ) ?;
363
- buffer[ ..len] . copy_from_slice ( bytes) ;
364
- // This is ok because the buffer was strictly larger than `bytes`, so after adding the
365
- // null terminator, the buffer size is larger or equal to `bytes.len()`, meaning that
366
- // `bytes` actually fit inside tbe buffer.
367
- buffer[ len] = 0 ;
368
- Ok ( ( ) )
369
- } else {
370
- throw_unsup_format ! ( "OsString is larger than destination" )
359
+ if size <= bytes. len ( ) as u64 {
360
+ throw_unsup_format ! ( "OsString of length {} is too large for destination buffer of size {}" , len, size)
371
361
}
362
+
363
+ let this = self . eval_context_mut ( ) ;
364
+ let buffer = this. memory . get_mut ( ptr. alloc_id ) ?. get_bytes_mut ( & * this. tcx , ptr, Size :: from_bytes ( len as u64 + 1 ) ) ?;
365
+ buffer[ ..len] . copy_from_slice ( bytes) ;
366
+ // This is ok because the buffer was strictly larger than `bytes`, so after adding the
367
+ // null terminator, the buffer size is larger or equal to `bytes.len()`, meaning that
368
+ // `bytes` actually fit inside tbe buffer.
369
+ buffer[ len] = 0 ;
370
+ Ok ( ( ) )
372
371
}
373
372
}
374
373
0 commit comments