Commit 7ab38f93 authored by Sergio Costas's avatar Sergio Costas

Merge branch 'freed_not_null'

parents 8e1a5170 7060affb
This diff is collapsed.
......@@ -171,7 +171,8 @@ class Test(unittest.TestCase):
self._generic_test("unitest/test20.c", [ (crust.crust.MSG_ERROR, "Using uninitialized variable '{:s}' at line {:d}", "param4", 5) ])
def test021FreedVariable(self):
self._generic_test("unitest/test21.c", [ (crust.crust.MSG_ERROR, "Using variable '{:s}' at line {:d}, after being freed at line {:d}", "param4", 8, 7) ])
self._all_fine_test("unitest/test21.c")
#self._generic_test("unitest/test21.c", [ (crust.crust.MSG_ERROR, "Using variable '{:s}' at line {:d}, after being freed at line {:d}", "param4", 8, 7) ])
def test022AssignFreedVariable(self):
self._generic_test("unitest/test22.c", [ (crust.crust.MSG_ERROR, "Using variable '{:s}' at line {:d}, after being freed at line {:d}", "param1", 5, 4), (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param4", 4, 7) ])
......@@ -330,8 +331,8 @@ class Test(unittest.TestCase):
def test072AliasFreesBlock(self):
lib = self._all_fine_test("unitest/test72.c")
self._check_var_state(lib, "param", crust.crust.VALUE_FREED)
self._check_var_state(lib, "an_alias", crust.crust.VALUE_FREED)
self._check_var_state(lib, "param", crust.crust.VALUE_FREED_OR_NULL)
self._check_var_state(lib, "an_alias", crust.crust.VALUE_FREED_OR_NULL)
def test073AliasFreesBlock2(self):
self._generic_test("unitest/test73.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "main", 9, 8) ])
......@@ -342,21 +343,21 @@ class Test(unittest.TestCase):
def test075DecoupleAlias(self):
lib = self._generic_test("unitest/test75.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "main", 13, 9) ])
self._check_var_state(lib, "an_alias", crust.crust.VALUE_NOT_NULL_OR_NULL, 0)
self._check_var_state(lib, "an_alias", crust.crust.VALUE_FREED, 1)
self._check_var_state(lib, "an_alias", crust.crust.VALUE_FREED_OR_NULL, 1)
self._check_var_state(lib, "an_alias", crust.crust.VALUE_NULL, 2)
def test076DecoupleAlias2(self):
lib = self._all_fine_test("unitest/test76.c")
self._check_var_state(lib, "param1", crust.crust.VALUE_FREED, 0)
self._check_var_state(lib, "param1", crust.crust.VALUE_FREED_OR_NULL, 0)
self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL_OR_NULL, 0)
self._check_var_state(lib, "an_alias", crust.crust.VALUE_NOT_NULL_OR_NULL, 0)
self._check_var_state(lib, "param2", crust.crust.VALUE_FREED, 1)
self._check_var_state(lib, "an_alias", crust.crust.VALUE_FREED, 1)
self._check_var_state(lib, "param2", crust.crust.VALUE_FREED_OR_NULL, 1)
self._check_var_state(lib, "an_alias", crust.crust.VALUE_FREED_OR_NULL, 1)
def test077DecoupleAlias3(self):
lib = self._generic_test("unitest/test77.c", [ (crust.crust.MSG_ERROR, "Assigning the crust-type result value of function '{:s}' to the alias '{:s}' at line {:d}", "function", "an_alias", 11) ])
self._check_var_state(lib, "param", crust.crust.VALUE_FREED, 1)
self._check_var_state(lib, "param", crust.crust.VALUE_FREED_OR_NULL, 1)
self._check_var_state(lib, "an_alias", crust.crust.VALUE_NOT_NULL_OR_NULL, 1)
def test078FunctionPointerNull(self):
......@@ -559,10 +560,10 @@ class Test(unittest.TestCase):
self._check_block_id_is_the_same(lib, "param2", "alias1", 3)
self._check_block_id_is_the_same(lib, "param1", "alias2", 3)
self._check_var_state(lib, "param1", crust.crust.VALUE_FREED, 4)
self._check_var_state(lib, "param1", crust.crust.VALUE_FREED_OR_NULL, 4)
self._check_var_state(lib, "param2", crust.crust.VALUE_FREED, 4)
self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED, 4)
self._check_var_state(lib, "alias2", crust.crust.VALUE_FREED, 4)
self._check_var_state(lib, "alias2", crust.crust.VALUE_FREED_OR_NULL, 4)
def test130AssignAliasFromAlias(self):
......@@ -589,7 +590,7 @@ class Test(unittest.TestCase):
self._check_block_id_is_the_same(lib, "param", "alias2", 3)
self._check_var_state(lib, "param", crust.crust.VALUE_NOT_NULL, 4)
self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED, 4)
self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED_OR_NULL, 4)
self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL, 4)
self._check_block_id_is_not_same(lib, "param", "alias1", 4)
self._check_block_id_is_the_same(lib, "param", "alias2", 4)
......@@ -639,15 +640,15 @@ class Test(unittest.TestCase):
self._check_block_id_is_the_same(lib, "param1", "alias1", 2)
self._check_block_id_is_the_same(lib, "param2", "alias2", 2)
self._check_var_state(lib, "param1", crust.crust.VALUE_FREED, 3)
self._check_var_state(lib, "param1", crust.crust.VALUE_FREED_OR_NULL, 3)
self._check_var_state(lib, "param2", crust.crust.VALUE_NOT_NULL, 3)
self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED, 3)
self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED_OR_NULL, 3)
self._check_var_state(lib, "alias2", crust.crust.VALUE_NOT_NULL, 3)
self._check_block_id_is_the_same(lib, "param2", "alias2", 3)
self._check_var_state(lib, "param1", crust.crust.VALUE_FREED, 4)
self._check_var_state(lib, "param1", crust.crust.VALUE_FREED_OR_NULL, 4)
self._check_var_state(lib, "param2", crust.crust.VALUE_FREED, 4)
self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED, 4)
self._check_var_state(lib, "alias1", crust.crust.VALUE_FREED_OR_NULL, 4)
self._check_var_state(lib, "alias2", crust.crust.VALUE_FREED, 4)
......@@ -986,7 +987,19 @@ class Test(unittest.TestCase):
self._generic_test("unitest/test237.c", [ (crust.crust.MSG_ERROR, "Using uninitialized variable '{:s}' at line {:d}", "p", 7) ])
def test238CompareWithCrustPointerAloneFreed(self):
self._generic_test("unitest/test238.c", [ (crust.crust.MSG_ERROR, "Using variable '{:s}' at line {:d}, after being freed at line {:d}", "p", 9, 7) ])
self._all_fine_test("unitest/test238.c")
def test239NullCrustPointerIsNotFreed(self):
self._all_fine_test("unitest/test239.c")
def test240CompareWithCrustPointerAloneFreedNotNull(self):
self._all_fine_test("unitest/test240.c")
def test241CompareFreedWithNull(self):
self._all_fine_test("unitest/test241.c")
def test242CompareWithCrustPointerWithNullUninitialized(self):
self._generic_test("unitest/test242.c", [ (crust.crust.MSG_ERROR, "Using uninitialized variable '{:s}' at line {:d}", "p", 7) ])
if __name__ == '__main__':
try:
......
......@@ -21,7 +21,7 @@ void main(crust_t param1, crust_t __crust_not_null__ param2) {
__crust_debug__ // here, 'param1', 'alias1' must be NOT_NULL_OR_NULL and share UID, 'param2', 'alias2' must be NOT_NULL and share UID
alias2->next = alias1;
__crust_debug__ // here 'param1', 'alias1' must be FREED, 'param2', 'alias2' must be NOT_NULL and share UID
__crust_debug__ // here 'param1', 'alias1' must be FREED_OR_NULL, 'param2', 'alias2' must be NOT_NULL and share UID
function(param2);
__crust_debug__ // here 'param1', 'alias1', 'param2', 'alias2' must be FREED
__crust_debug__ // here 'param1' and 'alias1' must be FREED_OR_NULL, and 'param2', 'alias2' must be FREED
}
......@@ -2,9 +2,9 @@ typedef __crust__ unsigned char *crust_t;
int function2(crust_t param1);
void function(crust_t param1) {
crust_t param4 = NULL;
void function(crust_t param1, crust_t param4) {
int retval = function2(param4);
retval = (param4 == param1) ? 1 : 0; // ERROR: condition depends on a freed variable
retval = (param4 == param1) ? 1 : 0; // NO ERROR: param4 has been freed, but still can be compared
retval = function2(param1);
}
......@@ -4,9 +4,11 @@ void function(crust_t);
void main(crust_t p) {
// Here, p in in NOT_NULL_OR_NULL state
function(p);
// Now, p is in FREED_OR_NULL state
if (!p) { // ERROR; p has already been freed
if (!p) { // NO ERROR, because we are just comparing
p = NULL;
}
}
typedef __crust__ unsigned char *crust_t;
void function(crust_t);
void main() {
crust_t p = NULL;
// Here, p in in NULL state
function(p);
if (!p) { // NO ERROR; p is NULL
p = NULL;
}
}
typedef __crust__ unsigned char *crust_t;
void function(crust_t);
void main(crust_t __crust_not_null__ p) {
// Here, p in in NOT_NULL state
function(p);
// Now, p is in FREED state
if (!p) { // NO ERROR, because we are just comparing
p = NULL;
}
}
typedef __crust__ unsigned char *crust_t;
void function(crust_t);
void main(crust_t evento) {
function(evento);
if (evento != NULL) {
evento = NULL;
}
}
\ No newline at end of file
typedef __crust__ unsigned char *crust_t;
void main() {
crust_t p;
if (p == NULL) { // ERROR; p isn't initialized
p = NULL;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment