Commit 15db8fd0 authored by Sergio Costas's avatar Sergio Costas

Now checks wether a pointer is being compared after being freed or before being initialized

parent 80a46699
......@@ -521,6 +521,8 @@ class crust(object):
if self._check_statement_is_crust(statement, vardata):
valuetype = self.TYPE_CRUST
pure = True
if is_conditional:
self._check_can_be_used(thread_status, statement, statement.line)
if (valuedata == self.VALUE_NOT_NULL_OR_NULL) and is_conditional:
var1 = self._copy_status(thread_status)
var2 = thread_status
......
......@@ -982,6 +982,12 @@ class Test(unittest.TestCase):
def test236CompareWithCrustPointerAlone4(self):
self._generic_test("unitest/test236.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "p", 5, 12) ])
def test237CompareWithCrustPointerAloneUninitialized(self):
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) ])
if __name__ == '__main__':
try:
os.remove("error_list.txt")
......
typedef __crust__ unsigned char *crust_t;
void main() {
crust_t p;
if (!p) { // ERROR; p isn't initialized
p = NULL;
}
}
typedef __crust__ unsigned char *crust_t;
void function(crust_t);
void main(crust_t p) {
function(p);
if (!p) { // ERROR; p has already been freed
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