Skip to content

Commit ab05967

Browse files
committed
Change comparison order for clarity
1 parent 0201cc5 commit ab05967

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/helpers.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,19 +356,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
356356
let len = bytes.len();
357357
// If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required null
358358
// 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)
371361
}
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(())
372371
}
373372
}
374373

0 commit comments

Comments
 (0)