提交 2d5c4196 编写于 作者: O Oliver Schneider 提交者: GitHub

Merge pull request #254 from RalfJung/dangling

Remove reundant dangling checks in {r,d}eallocate
......@@ -230,7 +230,7 @@ pub fn allocate(&mut self, size: u64, align: u64, kind: Kind) -> EvalResult<'tcx
pub fn reallocate(&mut self, ptr: MemoryPointer, old_size: u64, old_align: u64, new_size: u64, new_align: u64, kind: Kind) -> EvalResult<'tcx, MemoryPointer> {
use std::cmp::min;
if ptr.offset != 0 || self.get(ptr.alloc_id).is_err() {
if ptr.offset != 0 {
return Err(EvalError::ReallocateNonBasePtr);
}
if let Ok(alloc) = self.get(ptr.alloc_id) {
......@@ -248,7 +248,7 @@ pub fn reallocate(&mut self, ptr: MemoryPointer, old_size: u64, old_align: u64,
}
pub fn deallocate(&mut self, ptr: MemoryPointer, size_and_align: Option<(u64, u64)>, kind: Kind) -> EvalResult<'tcx> {
if ptr.offset != 0 || self.get(ptr.alloc_id).is_err() {
if ptr.offset != 0 {
return Err(EvalError::DeallocateNonBasePtr);
}
......
......@@ -5,7 +5,7 @@
use alloc::heap::Heap;
use alloc::allocator::*;
// error-pattern: tried to deallocate with a pointer not to the beginning of an existing object
// error-pattern: tried to deallocate dangling pointer
use alloc::heap::*;
fn main() {
......
#![feature(alloc, allocator_api)]
extern crate alloc;
use alloc::heap::Heap;
use alloc::allocator::*;
// error-pattern: dangling pointer was dereferenced
use alloc::heap::*;
fn main() {
unsafe {
let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap();
Heap.dealloc(x, Layout::from_size_align_unchecked(1, 1));
Heap.realloc(x, Layout::from_size_align_unchecked(1, 1), Layout::from_size_align_unchecked(1, 1));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册