Commit 759e3bd7 authored by Sergio Costas's avatar Sergio Costas

Now doesn't allow freed global variables at the end of a function

parent 4c63d373
......@@ -1302,6 +1302,7 @@ class crust(object):
if self.verbose:
print(" " * total_len + "\r", end = "")
def _process_block(self, function_name, tree, thread_status):
thread_status["debug_level"] = 0
......@@ -1336,6 +1337,19 @@ class crust(object):
print("\n\n")
def _check_global_vars(self, thread_status, line):
# check that there are no global vars with the same block,
# neither global vars in FREED state
for variable in thread_status["variables"][-1]:
data = thread_status["variables"][-1][variable]
if not data["crust"]:
continue
if not data["global"]:
continue
if data["value"] == self.VALUE_FREED:
self._add_error(thread_status, self.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to a block freed at line {:d}.", line, variable, data["init_line"])
def _check_blocks_in_use(self, thread_status, vars, line):
# check if there are memory blocks in use
for variable in vars:
......@@ -1355,9 +1369,9 @@ class crust(object):
if not found:
init_line = data["init_line"]
if init_line is None:
self._add_error(thread_status, self.MSG_ERROR, "Memory block '{:s}' is still in use at exit point at line {:d}", variable, line)
self._add_error(thread_status, self.MSG_ERROR, "Memory block '{:s}' is still in use at exit point in line {:d}", variable, line)
else:
self._add_error(thread_status, self.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point at line {:d}", variable, init_line, line)
self._add_error(thread_status, self.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", variable, init_line, line)
def _process_block2(self, tree, thread_status):
......@@ -1396,6 +1410,7 @@ class crust(object):
if node.type == "END_BLOCK":
# check if there are blocks in use at the end of the block
self._check_blocks_in_use(thread_status, thread_status["variables"][0], node.line)
self._check_global_vars(thread_status, node.line)
# remove the last block of variables
thread_status["variables"] = thread_status["variables"][1:]
return self._check_return_block(tree[1:], thread_status)
......@@ -1482,6 +1497,7 @@ class crust(object):
while(len(tmp_status["variables"]) > 1):
self._check_blocks_in_use(tmp_status, tmp_status["variables"][0], node.line)
tmp_status["variables"] = tmp_status["variables"][1:]
self._check_global_vars(thread_status, node.line)
if tmp_status["returned_something"] == True:
if (thread["type"] == self.TYPE_CRUST) and (tmp_status["return_is_crust"] == False):
......
This diff is collapsed.
typedef __crust_t__ unsigned char *crust_t;
typedef void (*test)(void);
crust_t var1;
void function(crust_t);
void main(crust_t __crust_not_null__ arg1) {
if (var1 == NULL) {
var1 = arg1;
}
function(arg1);
// ERROR: there is a global variable with FREED status at exit
}
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