Commit cc61fa40 authored by Sergio Costas's avatar Sergio Costas

Added extra test

parent 2cd445e8
......@@ -805,7 +805,7 @@ class Test(unittest.TestCase):
self._generic_test("unitest/test183.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point in line {:d}", "param3", 5, 9) ])
def test184CheckAssignToSeveralGlobalVars(self):
lib = self._generic_test("unitest/test184.c", [ (crust.crust.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to the same block than global variable '{:s}'.", 18, "global_var1", "global_var2") ])
lib = self._generic_test("unitest/test184.c", [ (crust.crust.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to the same block than global variable '{:s}'.", 17, "global_var1", "global_var2") ])
self._check_block_id_is_the_same(lib, "param1", "global_var1")
self._check_block_id_is_the_same(lib, "param1", "global_var2")
......@@ -955,6 +955,8 @@ class Test(unittest.TestCase):
def test227TestAutoIncrement(self):
self._generic_test("unitest/test227.c", [ (crust.crust.MSG_CRITICAL, "Using autoincrement with __crust__ pointer '{:s}' at line {:d}", "param", 5), (crust.crust.MSG_CRITICAL, "Using autodecrement with __crust__ pointer '{:s}' at line {:d}", "param2", 6) ])
def test228AssignGlobalVarNotNull(self):
self._generic_test("unitest/test228.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, but it is not freed", "var1", 10) ])
if __name__ == '__main__':
try:
......
......@@ -9,8 +9,7 @@ void function(crust_t param1) {
if ((global_var1 == NULL) && (global_var2 == NULL)) {
global_var1 = param1; // It is fine: since we are storing the block from "param3" in a global variable, it is not a dangling pointer
global_var2 = param1; // It is fine to assign the same block to several global variables
// Here param1 is not freed, but is OK because it is in a global variable
global_var2 = param1; // It is NOT fine to assign the same block to several global variables
__crust_debug__
} else {
function(param1); // free param1 to avoid an error
......
typedef __crust__ unsigned char *crust_t;
crust_t var1;
void function(crust_t);
void main(crust_t __crust_not_null__ arg1) {
if (var1 != NULL) {
var1 = arg1;
} else {
function(arg1);
}
// ERROR: can't assign a value to var1 when it is not NULL
}
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