Commit dbcf6fae authored by Sergio Costas's avatar Sergio Costas

Now works fine with arrays

parent 80362e28
...@@ -336,7 +336,7 @@ class crusty(object): ...@@ -336,7 +336,7 @@ class crusty(object):
error_found = True error_found = True
continue continue
node_var = self._find_variable(newvar_container,variable.name,node.line) node_var = self._find_variable(newvar_container,variable.name,node.line)
var_is_crusty = self._check_variable_properties(node_var,self.PROPERTY_CRUST_VARIABLE) var_is_crusty = self._check_variable_properties(node_var,self.PROPERTY_CRUST_VARIABLE) and (node_var["pointer"] == 1)
param_is_crusty = ((function_data[pos+1][0] & self.PROPERTY_CRUST_VARIABLE) != 0) and (function_data[pos+1][1] == 1) param_is_crusty = ((function_data[pos+1][0] & self.PROPERTY_CRUST_VARIABLE) != 0) and (function_data[pos+1][1] == 1)
param_is_borrowed = ((function_data[pos+1][0] & self.PROPERTY_BORROWED) != 0) and (function_data[pos+1][1] == 1) param_is_borrowed = ((function_data[pos+1][0] & self.PROPERTY_BORROWED) != 0) and (function_data[pos+1][1] == 1)
param_is_recycled = ((function_data[pos+1][0] & self.PROPERTY_RECYCLED) != 0) and (function_data[pos+1][1] == 1) param_is_recycled = ((function_data[pos+1][0] & self.PROPERTY_RECYCLED) != 0) and (function_data[pos+1][1] == 1)
...@@ -404,9 +404,12 @@ class crusty(object): ...@@ -404,9 +404,12 @@ class crusty(object):
elif assignment.type == "IDENTIFIER": elif assignment.type == "IDENTIFIER":
vardata = self._find_variable(var_container,assignment.name,assignment.line) vardata = self._find_variable(var_container,assignment.name,assignment.line)
if valuetype == self.TYPE_NO_CRUST: if valuetype == self.TYPE_NO_CRUST:
retval_type = self.TYPE_CRUST if ((vardata["properties"] & self.PROPERTY_CRUST_VARIABLE) != 0) else self.TYPE_NO_CRUST retval_type = self.TYPE_CRUST if (((vardata["properties"] & self.PROPERTY_CRUST_VARIABLE) != 0) and (vardata["pointer"] == 1)) else self.TYPE_NO_CRUST
else: else:
retval_type = valuetype retval_type = valuetype
if assignment.right is not None:
# for structs and arrays
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), self.TYPE_NO_MATTER, assignment.name) ]
if vardata["status"] == self.STATUS_UNINITIALIZED: if vardata["status"] == self.STATUS_UNINITIALIZED:
self._add_error(self.MSG_ERROR,"Using the value of '{:s}' at line {:d} in an assignment, but it is uninitialized",assignment.name,assignment.line) self._add_error(self.MSG_ERROR,"Using the value of '{:s}' at line {:d} in an assignment, but it is uninitialized",assignment.name,assignment.line)
return [ (self.STATUS_UNINITIALIZED, self._copy_container(var_container), retval_type, assignment.name) ] return [ (self.STATUS_UNINITIALIZED, self._copy_container(var_container), retval_type, assignment.name) ]
...@@ -508,7 +511,11 @@ class crusty(object): ...@@ -508,7 +511,11 @@ class crusty(object):
continue continue
if node.type == "VARIABLE_DEFINITION": if node.type == "VARIABLE_DEFINITION":
if not node.t_typedef: if not node.t_typedef:
var_container[0][node.name] = {"properties":self._get_variable_properties(node,False), "status":crusty.STATUS_GLOBAL, "init_line": None, "pointer": node.pointer, "enum": False } pointers = node.pointer
if node.arrays is not None:
for element in node.arrays:
pointers += 1
var_container[0][node.name] = {"properties":self._get_variable_properties(node,False), "status":crusty.STATUS_GLOBAL, "init_line": None, "pointer": pointers, "enum": False }
continue continue
if (node.type == "FUNCTION_DECLARATION") or (node.type == "FUNCTION_DEFINITION"): if (node.type == "FUNCTION_DECLARATION") or (node.type == "FUNCTION_DEFINITION"):
counter = 0 counter = 0
......
...@@ -151,5 +151,17 @@ class Test(unittest.TestCase): ...@@ -151,5 +151,17 @@ class Test(unittest.TestCase):
def testAmpPointer(self): def testAmpPointer(self):
self._all_fine_test("unitest/test35.c") self._all_fine_test("unitest/test35.c")
def testStructElement(self):
self._all_fine_test("unitest/test36.c")
def testStructAssign(self):
self._generic_test("unitest/test37.c",False,[ (crusty.crusty.MSG_CRITICAL,"Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}","test","param4",8) ])
def testArrayElement(self):
self._all_fine_test("unitest/test38.c")
def testArrayAssign(self):
self._generic_test("unitest/test39.c",False,[ (crusty.crusty.MSG_CRITICAL,"Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}","test","param4",6) ])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -2,6 +2,6 @@ typedef __crust_t__ unsigned char *crust_t; ...@@ -2,6 +2,6 @@ typedef __crust_t__ unsigned char *crust_t;
int function(int param3) { int function(int param3) {
crust_t *param = NULL; crust_t param = NULL;
function(param); // ERROR: passing a crust variable as a non-crust parameter function(param); // ERROR: passing a crust variable as a non-crust parameter
} }
...@@ -2,6 +2,6 @@ typedef __crust_t__ unsigned char *crust_t; ...@@ -2,6 +2,6 @@ typedef __crust_t__ unsigned char *crust_t;
crust_t function(int param3) { crust_t function(int param3) {
crust_t *param = NULL; crust_t param = NULL;
crust_t retval = function(param); // ERROR: passed a crust variable to a non-crust param crust_t retval = function(param); // ERROR: passed a crust variable to a non-crust param
} }
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