Commit b4d43da2 authored by Sergio Costas's avatar Sergio Costas

Added unitary tests to check if it detects blocks in use at the end of a block

parent 432e7077
......@@ -731,6 +731,21 @@ class crusty(object):
print("{:s} at line {:d}".format(node.type,node.line))
print("\n\n")
def _check_blocks_in_use(self,vars,line):
# check if there are memory blocks in use
for variable in vars:
data = vars[variable]
if not data["crust"]:
continue
init_line = data["init_line"]
if ((data["status"] == self.STATUS_NOT_NULL) or (data["status"] == self.STATUS_NOT_NULL_OR_NULL)) and (not data["borrowed"]):
if init_line is None:
self._add_error(self.MSG_ERROR,"Memory block '{:s}' still is in use at exit point at line {:d}",variable,line)
else:
self._add_error(self.MSG_ERROR,"Memory block '{:s}', initialized at line {:d}, is still in use at exit point at line {:d}",variable,init_line,line)
def _process_block2(self, tree, var_container):
node = tree[0]
......@@ -747,20 +762,10 @@ class crusty(object):
var_container.insert(0,{})
return self._check_return_block(tree[1:],var_container)
if node.type == "END_BLOCK":
current_block = var_container[0]
# check if there are blocks in use at the end of the block
self._check_blocks_in_use(var_container[0],node.line)
# remove the last block of variables
var_container = var_container[1:]
# check if there are memory blocks in use
for variable in current_block:
data = current_block[variable]
if not data["crust"]:
continue
init_line = data["init_line"]
if ((data["status"] == self.STATUS_NOT_NULL) or (data["status"] == self.STATUS_NOT_NULL_OR_NULL)) and (not data["borrowed"]):
if init_line is None:
self._add_error(self.MSG_ERROR,"Memory block '{:s}' still is in use at exit point at line {:d}",variable,node.line)
else:
self._add_error(self.MSG_ERROR,"Memory block '{:s}', initialized at line {:d}, still is in use at exit point at line {:d}",variable,init_line,node.line)
return self._check_return_block(tree[1:],var_container)
if node.type == "EMPTY_DECLARATOR":
return self._check_return_block(tree[1:],var_container)
......
......@@ -258,5 +258,12 @@ class Test(unittest.TestCase):
def testReturn(self):
self._all_fine_test("unitest/test62.c")
def testBlockInUseAtEnd(self):
self._generic_test("unitest/test63.c",[ (crusty.crusty.MSG_ERROR,"Memory block '{:s}', initialized at line {:d}, is still in use at exit point at line {:d}","param",5,8) ])
def testBlockInUseAtEnd2(self):
self._generic_test("unitest/test64.c",[ (crusty.crusty.MSG_ERROR,"Memory block '{:s}', initialized at line {:d}, is still in use at exit point at line {:d}","param",5,7) ])
if __name__ == '__main__':
unittest.main()
......@@ -7,5 +7,5 @@ void main(crust_t param) {
crust_t var2;
var2 = param;
return;
main2(param); // will not fail because there is a RETURN before
main(param);
}
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void main(crust_t param) {
main(NULL);
// ERROR: param is not managed at the end of the block
}
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void main(crust_t param) {
// ERROR: param is not managed at the end of the block
}
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