Commit 3702584a authored by Sergio Costas's avatar Sergio Costas

Now doesn't show a "not initialized" error when assigning a value to an...

Now doesn't show a "not initialized" error when assigning a value to an element in an struct, when the struct is not a pointer
parent 77387914
......@@ -635,7 +635,8 @@ class crust(object):
elif (dest_data["value"] == self.VALUE_NOT_NULL_OR_NULL) and (dest_data["crust"]) and (not dest_data["global"]):
self._add_error(orig_eval["thread_status"], self.MSG_WARNING, "Using variable '{:s}' at line {:d} with a possible NULL value", dest_data["name"], statement.line)
elif dest_data["value"] == self.VALUE_UNINITIALIZED:
self._add_error(orig_eval["thread_status"], self.MSG_ERROR, "Using variable '{:s}' at line {:d}, but it hasn't been initialized yet", dest_data["name"], statement.line)
if (dest_var.right is None) or (dest_var.right[0].type != "."):
self._add_error(orig_eval["thread_status"], self.MSG_ERROR, "Using variable '{:s}' at line {:d}, but it hasn't been initialized yet", dest_data["name"], statement.line)
elif dest_data["value"] == self.VALUE_FREED:
self._add_error(orig_eval["thread_status"], self.MSG_ERROR, "Using variable '{:s}' at line {:d}, but it has been already freed", dest_data["name"], statement.line)
......
......@@ -801,6 +801,15 @@ class Test(unittest.TestCase):
def test192GlobalVariableFreedAtExit(self):
self._generic_test("unitest/test192.c", [ (crust.crust.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to a block freed at line {:d}.", 16, "var1", 14) ])
def test193GlobalVariableFreedAtExit(self):
lib = self._generic_test("unitest/test193.c", [ (crust.crust.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to the same block than global variable '{:s}'.", 20, "var1", "var2") ])
self._check_block_id_is_the_same(lib, "arg1", "var1")
self._check_block_id_is_the_same(lib, "arg1", "var2")
def test194GlobalVariableFreedAtExit(self):
lib = self._all_fine_test("unitest/test194.c")
self._check_var_status(lib, "global_var", crust.crust.VALUE_NOT_NULL_OR_NULL)
if __name__ == '__main__':
try:
......
typedef __crust_t__ unsigned char *crust_t;
typedef void (*test)(void);
crust_t var1;
crust_t var2;
void function(crust_t);
void main(crust_t __crust_not_null__ arg1) {
if ((var1 == NULL) && (var2 == NULL)) {
var1 = arg1;
var2 = arg1;
} else {
function(arg1);
}
__crust_debug__
// ERROR: there are two global variables pointing to the same block
}
typedef __crust_t__ unsigned char *crust_t;
typedef void (*test)(void);
struct {
char var1;
int var2;
} global_var;
void function(crust_t);
void main(crust_t __crust_not_null__ var) {
global_var.var1 = var; // this is fine
__crust_debug__
}
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