Commit 1524588e authored by Sergio Costas's avatar Sergio Costas

Fixed the inners of SWITCH (the DEFAULT could fail)

Now, when defining an array but not initializing it, the array name (which is a pointer to the array) is considered initialized
parent c8d02168
......@@ -817,7 +817,7 @@ class crust(object):
if param2.t_null and (param1.type == "IDENTIFIER"):
# check cases of CRUST_VAR == NULL or NULL == CRUST_VAR
var_data = self._find_variable(thread_status, param1.name, statement.line)
if var_data["crust"] or (((var_data["pointer"] != 0) or ((var_data["function_params"] is not None) and (var_data["value"] != self.VALUE_FUNCTION))) and (param1.right is None)):
if var_data["crust"] or (((var_data["pointer"] != 0) or ((var_data["function_params"] is not None) and (var_data["value"] != self.VALUE_FUNCTION))) and (param1.right is None) and (param1.arrays is None)):
if statement.type == "EQ_OP":
cd1 = self.CONDITION_FALSE
cd2 = self.CONDITION_TRUE
......@@ -1460,7 +1460,10 @@ class crust(object):
self._process_enum(node, thread_status)
varname = node.name
var_defined = self._get_variable_properties(thread_status, node, node.pointer, False)
var_defined["value"] = crust.VALUE_UNINITIALIZED
if node.arrays is None:
var_defined["value"] = crust.VALUE_UNINITIALIZED
else:
var_defined["value"] = crust.VALUE_NOT_NULL
var_defined["init_line"] = None
var_defined["enum"] = False
#var_defined = self._node_fill_parameters(thread_status, node, var_defined)
......@@ -1640,6 +1643,8 @@ class crust(object):
default_block = switch_block[1:]
switch_block = switch_block[1:]
threads = []
block_zero = None
block_no_zero = None
for block in blocks:
code = blocks[block][:]
# create a comparison for equal
......@@ -1649,21 +1654,30 @@ class crust(object):
condition_true.name = ""
condition_true.child1 = [ first_part.copy() ]
condition_true.child2 = [ block.condition[0].copy() ]
if block.condition[0].t_null:
if block_zero is None:
block_zero = block.condition[0].copy()
else:
if block_no_zero is None:
block_no_zero = block.condition[0].copy()
# prepend the comparison evaluation before the code block
code.insert(0, self._new_eval_true(condition_true))
code.insert(0, self._new_start_block())
code += [self._new_end_loop(), self._new_end_block()] + other_block[:]
threads += self._check_return_block(code, self._copy_status(thread_status))
if default_block is not None:
# create a comparison for not equal for the default part
if default_block is not None:
# create a comparison for not equal for the default part
if (block_zero is not None) or (block_no_zero is not None):
condition_false = self.AST_node()
condition_false.type = "NE_OP"
condition_false.line = -1
condition_false.name = ""
condition_false.child1 = [ first_part.copy() ]
condition_false.child2 = [ block.condition[0].copy() ]
if block_zero is not None:
condition_false.child2 = [ block_zero ]
else:
condition_false.child2 = [ block_no_zero ]
default_block.insert(0, self._new_eval_false(condition_false))
if default_block is not None:
default_block.insert(0, self._new_start_block())
default_block += [self._new_end_loop(), self._new_end_block()] + other_block[:]
threads += self._check_return_block(default_block, self._copy_status(thread_status))
......
......@@ -851,6 +851,10 @@ class Test(unittest.TestCase):
def test206SwitchWithPointerContent(self):
self._all_fine_test("unitest/test206.c")
def test207SwitchWithPointerContent(self):
lib = self._all_fine_test("unitest/test207.c")
self._check_var_state(lib, "str", crust.crust.VALUE_NOT_NULL)
if __name__ == '__main__':
try:
os.remove("error_list.txt")
......
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void main() {
char str[5];
__crust_debug__
str[2] = 0; // This is fine
}
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