Commit 074adb47 authored by Sergio Costas's avatar Sergio Costas

Fix switch/case without default statement

When a switch/case lacks a default statement, crust fails to follow the
case when the variable doesn't fit any of the defined cases (see unitary
test 252).

This patch fixes this.
parent 38e6fe04
......@@ -1129,14 +1129,10 @@ class crust(crust_helpers):
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))
if len(threads) == 0:
return [ (None, thread_status) ]
# if thread_status["current_function"] == "comandos_set_var":
# for t in threads:
# print("Bloque:")
# self._print_tree(t[0])
return threads
threads += self._check_return_block(other_block, self._copy_status(thread_status))
return threads
if (node.type == "EVAL_TRUE") or (node.type == "EVAL_FALSE"):
threads = self._eval_statement(node.condition, self._copy_status(thread_status), False, True)
......@@ -1027,6 +1027,9 @@ class Test(unittest.TestCase):
def test251NoVoidOnEmptyParameterFunctionAndDefinitionInHeader(self):
self._generic_test("unitest/test251.c", [ (crust.crust.MSG_ERROR, "Function '{:s}' at line {:d} in file '{:s}' has no parameters (must have 'void' inside the parentheses)", 'function', 4, 'unitest/test251.h'), (crust.crust.MSG_ERROR, "Function '{:s}' at line {:d} has no parameters (must have 'void' inside the parentheses)", 'function', 12) ])
def test252switchWithoutDefault(self):
self._generic_test("unitest/test252.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", 'param', 5, 19) ])
if __name__ == '__main__':
typedef __crust__ unsigned char *crust_t;
void function(crust_t param);
void main(crust_t param, int a) {
switch (a) {
case 0:
case 1:
case 2:
// ERROR: if 'a' is 3 or more, param isn't freed
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