[cfe-dev] Asan bug or feature?

miroslav.fontan miroslav.fontan at wincor-nixdorf.cz
Mon May 19 12:51:28 PDT 2014


Hi all,

By hunting after address error in our app I have found unexpected asan
behaviour

Here is a minimal isolated example which runs without address error:

clang++ a.cpp -fsanitize=address 

cat a.cpp

char* subroutine()
{
	char* p = new char[8]();
	return p;
}

int main( int /*argc*/, char** /*argv*/ )
{
	char* pc_sub = subroutine();
	char* pc_main = new char[8]();
	pc_main[32] = 1; //points to pc_sub, no ERROR :-(
//	pc_main[16] = 2; //points to bad address ERROR :-)
	pc_sub[-32] = 3; //points to pc_main, no ERROR :-(
	delete[] pc_main;
	delete[] pc_sub;
	return 0;
}

Regards

Miroslav






More information about the cfe-dev mailing list