Safe method wont check dangling pointer?

lzzll ownrepos at gmail.com
Mon Apr 14 16:28:06 PDT 2014


Looks like dangling point is not checked even in method mark as 
safe.
Example:
---
import std.stdio;

class A {
	int value;
	void set_value(int value) @safe {
		this.value = value;
	}
}

void test_safe(A a) @safe {
	a.set_value(1);
}

int main(string[] args) {
	A a = new A();
	test_safe(a);
	test_safe(null);
	test_safe(*(&a+100));
	
	writeln("done.");
	return 0;
}
---
test_safe(null);
and
test_safe(*(&a+100));
will cause segmentation fault.

I guess reason is check dangling pointer is very inefficient.
I found another post about this
http://forum.dlang.org/thread/llezieyytpcbcaoqeajz@forum.dlang.org#post-miyvktgkczatvoguawda:40forum.dlang.org
null pointer is not a safety problem, but pointer like *(&a+100) 
maybe.

Regard.


More information about the Digitalmars-d mailing list