Commit e69a65c4 authored by Sergio Costas's avatar Sergio Costas

Added support for DO...WHILE loops

parent 22c1ed69
......@@ -1245,6 +1245,17 @@ class crust(object):
retvals += self._check_return_block([self._new_start_block(), self._new_eval_true(condition)] + wblock[1:-1] + [self._new_eval_true(condition)] + wblock[1:-1] + [self._new_eval_false(condition), self._new_end_block(), self._new_end_loop()] + other_block[:], self._copy_container(var_container))
return retvals
if node.type == "DO":
var_container["loop_level"] += 1
condition = node.condition[0]
wblock, other_block = self._get_next_block(tree[1:])
retvals = []
# loop executed one time
retvals += self._check_return_block([self._new_start_block()] + wblock[1:-1] + [self._new_eval_false(condition), self._new_end_block(), self._new_end_loop()] + other_block[:], self._copy_container(var_container))
# loop executed two times
retvals += self._check_return_block([self._new_start_block()] + wblock[1:-1] + [self._new_eval_true(condition)] + wblock[1:-1] + [self._new_eval_false(condition), self._new_end_block(), self._new_end_loop()] + other_block[:], self._copy_container(var_container))
return retvals
if (node.type == "EVAL_TRUE") or (node.type == "EVAL_FALSE"):
values = self._eval_statement(node.condition, var_container)
retvals = []
......
......@@ -466,6 +466,15 @@ class Test(unittest.TestCase):
def test119CallingPointerWithPosibleNull(self):
self._generic_test("unitest/test119.c", [ (crust.crust.MSG_WARNING, "Using function pointer '{:s}' at line {:d} with a possible NULL value", "test1", 9) ])
def test120DoWhileUsesTwice(self):
self._generic_test("unitest/test120.c", [ (crust.crust.MSG_ERROR, "Parameter {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "main", 10, 10) ])
def test121DoWhileExitsFine(self):
self._all_fine_test("unitest/test121.c")
def test122DoWhileExitsBreak(self):
self._all_fine_test("unitest/test122.c")
if __name__ == '__main__':
try:
os.remove("error_list.txt")
......
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void main(crust_t param) {
int b = 0;
do {
main(param);
} while (b == 0);
// ERROR: since b is zero, param will never be freed
}
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void main(crust_t param) {
do {
if (param == NULL) {
param = (crust_t) 1;
}
} while(param == NULL);
main(param); // No error
}
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void function(crust_t param);
void main(int b) {
crust_t param;
do {
param = (crust_t) 1;
break;
} while(b);
function(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