Ensure that the passed in raw pointer is not used in SetRaw().

Review URL: http://codereview.chromium.org//8231028

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@404 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
asiva@google.com 2011-10-13 17:10:35 +00:00
parent 85804080f3
commit 9c927f8e02
2 changed files with 13 additions and 20 deletions

View file

@ -677,15 +677,6 @@ RawObject* Object::Allocate(const Class& cls,
}
#if defined(DEBUG)
void Object::ValidateHeapObject(RawObject* raw_obj) {
uword addr = RawObject::ToAddr(raw_obj);
ASSERT(Isolate::Current()->heap()->Contains(addr) ||
Dart::vm_isolate()->heap()->Contains(addr));
}
#endif // defined(DEBUG)
RawString* Class::Name() const {
if (raw_ptr()->name_ != String::null()) {
return raw_ptr()->name_;

View file

@ -6,6 +6,7 @@
#define VM_OBJECT_H_
#include "vm/assert.h"
#include "vm/dart.h"
#include "vm/globals.h"
#include "vm/handles.h"
#include "vm/heap.h"
@ -296,10 +297,6 @@ CLASS_LIST_NO_OBJECT(DEFINE_CLASS_TESTER);
return reinterpret_cast<cpp_vtable*>(reinterpret_cast<word>(this));
}
#if defined(DEBUG)
void ValidateHeapObject(RawObject* raw_obj);
#endif // defined(DEBUG)
static cpp_vtable handle_vtable_;
// The static values below are singletons shared between the different
@ -2767,17 +2764,22 @@ RawClass* Object::clazz() const {
void Object::SetRaw(RawObject* value) {
// NOTE: The assignment "raw_ = value" should be the first statement in
// this function. Also do not use 'value' in this function after the
// assignment (use 'raw_' instead).
raw_ = value;
uword raw_value = reinterpret_cast<uword>(value);
if ((raw_value & kSmiTagMask) == kSmiTag) {
if ((reinterpret_cast<uword>(raw_) & kSmiTagMask) == kSmiTag) {
set_vtable(Smi::handle_vtable_);
return;
}
#if defined(DEBUG)
ValidateHeapObject(value);
#endif // defined(DEBUG)
set_vtable((value == null_) ?
handle_vtable_ : value->ptr()->class_->ptr()->handle_vtable_);
#ifdef DEBUG
Heap* isolate_heap = Isolate::Current()->heap();
Heap* vm_isolate_heap = Dart::vm_isolate()->heap();
ASSERT(isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())) ||
vm_isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())));
#endif
set_vtable((raw_ == null_) ?
handle_vtable_ : raw_->ptr()->class_->ptr()->handle_vtable_);
}