Commit 7060affb authored by Sergio Costas's avatar Sergio Costas

Now doesn't fail when comparing a freed pointer specifically with NULL

parent 8f78aa9e
......@@ -430,7 +430,7 @@ class crust(object):
if varname["value"] == crust.VALUE_UNINITIALIZED:
self._add_error(thread_status, self.MSG_ERROR, "Using uninitialized variable '{:s}' at line {:d}", variable.name, line_number)
return
if (not comparison) and ((varname["value"] == crust.VALUE_FREED) or (varname["value"] == crust.VALUE_FREED_OR_NULL)):
if (comparison == False) and ((varname["value"] == crust.VALUE_FREED) or (varname["value"] == crust.VALUE_FREED_OR_NULL)):
self._add_error(thread_status, self.MSG_ERROR, "Using variable '{:s}' at line {:d}, after being freed at line {:d}", variable.name, line_number, varname["init_line"])
return
......@@ -600,7 +600,6 @@ class crust(object):
retvals = []
for orig_eval in threads:
dest_data = self._find_variable(orig_eval["thread_status"], dest_var.name, statement.line)
dest_status = dest_data["value"]
orig_type = orig_eval["type"]
orig_var = orig_eval["node"]
if orig_var is not None:
......@@ -891,8 +890,6 @@ class crust(object):
if (statement.type == "EQ_OP") or (statement.type == "NE_OP"):
self._check_is_freed(thread_status, statement.child1[0])
self._check_is_freed(thread_status, statement.child2[0])
retvals = []
threads1 = self._eval_statement(statement.child1[0], thread_status, False, True)
if statement.type == "EQ_OP":
......@@ -1102,17 +1099,6 @@ class crust(object):
return [ {"thread_status":thread_status, "value":self.VALUE_NOT_NULL_OR_NULL, "type":self.TYPE_NO_CRUST, "condition":self.CONDITION_FALSE_TRUE, "node":None, "pure": True} ]
def _check_is_freed(self, thread_status, statement):
if statement.type == "IDENTIFIER":
var_data = self._find_variable(thread_status, statement.name, statement.line)
if var_data["crust"]:
status = var_data["value"]
if status == crust.VALUE_UNINITIALIZED:
self._add_error(thread_status, self.MSG_ERROR, "Using uninitialized variable '{:s}' at line {:d}", statement.name, statement.line)
elif (status == crust.VALUE_FREED) or (status == crust.VALUE_FREED_OR_NULL):
self._add_error(thread_status, self.MSG_ERROR, "Using variable '{:s}' at line {:d}, after being freed at line {:d}", statement.name, statement.line, var_data["init_line"])
def _get_next_block(self, current_block):
""" Given a piece of the tree, cuts it in two subtrees: one with the block
......
......@@ -171,8 +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._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) ])
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) ])
......@@ -992,9 +992,15 @@ class Test(unittest.TestCase):
def test239NullCrustPointerIsNotFreed(self):
self._all_fine_test("unitest/test239.c")
def test238CompareWithCrustPointerAloneFreed2(self):
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:
os.remove("error_list.txt")
......
......@@ -5,6 +5,6 @@ int function2(crust_t param1);
void function(crust_t param1, crust_t param4) {
int retval = function2(param4);
retval = (param4 == param1) ? 1 : 0; // ERROR: param4 has already been freed
retval = (param4 == param1) ? 1 : 0; // NO ERROR: param4 has been freed, but still can be compared
retval = function2(param1);
}
......@@ -5,6 +5,7 @@ void function(crust_t);
void main() {
crust_t p = NULL;
// Here, p in in NULL state
function(p);
......
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