Commit f9af9fd5 authored by Sergio Costas's avatar Sergio Costas

Added exceptions for globar variables

parent 8b1ad064
......@@ -634,7 +634,7 @@ class crust(object):
if (dest_var.right is not None) and (dest_data["pointer"] != 0):
if dest_data["value"] == self.VALUE_NULL:
self._add_error(v["thread_status"], self.MSG_ERROR, "Using variable '{:s}' at line {:d} with a NULL value", dest_data["name"], statement.line)
elif (dest_data["value"] == self.VALUE_NOT_NULL_OR_NULL) and (dest_data["crust"]):
elif (dest_data["value"] == self.VALUE_NOT_NULL_OR_NULL) and (dest_data["crust"]) and (not dest_data["global"]):
self._add_error(v["thread_status"], self.MSG_WARNING, "Using variable '{:s}' at line {:d} with a possible NULL value", dest_data["name"], statement.line)
elif dest_data["value"] == self.VALUE_UNINITIALIZED:
self._add_error(v["thread_status"], self.MSG_ERROR, "Using variable '{:s}' at line {:d}, but it hasn't been initialized yet", dest_data["name"], statement.line)
......@@ -796,7 +796,7 @@ class crust(object):
if param_is_not_null:
if (var_data["value"] == self.VALUE_NULL):
self._add_error(thread["thread_status"], self.MSG_ERROR, "Argument '{:s}' at position {:d} when calling function '{:s}' at line {:d} is defined as not_null, but is being called with a NULL value", thread["node"].name, pos+1, statement.name, statement.line)
if var_data["value"] == self.VALUE_NOT_NULL_OR_NULL:
if (var_data["value"] == self.VALUE_NOT_NULL_OR_NULL) and (not var_data["global"]):
self._add_error(thread["thread_status"], self.MSG_WARNING, "Argument '{:s}' at position {:d} when calling function '{:s}' at line {:d} is defined as not_null, but is being called with a possible NULL value", thread["node"].name, pos+1, statement.name, statement.line)
if (not param_is_borrowed) and passed_is_crust and self._check_statement_is_crust(thread["node"], var_data):
......@@ -1295,11 +1295,9 @@ class crust(object):
tmpvars["return_cant_null"] = parameters[0]["not_null"]
if self.verbose:
blank_spc = (last_len - len(node.name)) if (len(node.name) < last_len) else 0
print(("\rProcessing {:s}" + " " * blank_spc).format(node.name), end = "")
print(("Processing {:s}" + " " * blank_spc + "\r").format(node.name), end = "")
last_len = len(node.name)
self._process_block(node.name, node.child1, tmpvars)
if self.verbose:
print()
def _process_block(self, function_name, tree, thread_status):
......
......@@ -837,6 +837,9 @@ class Test(unittest.TestCase):
def test186CheckIfWithUninitializedVariable(self):
self._generic_test("unitest/test186.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point at line {:d}", "data", 7, 11) ])
def test187GlobalVarsAlwaysNotNull(self):
self._all_fine_test("unitest/test187.c")
if __name__ == '__main__':
try:
os.remove("error_list.txt")
......
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
__crust_t__ struct {
int data;
} *global_data;
void main(int b) {
global_data->data = 5;
}
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