Commit 2cd445e8 authored by Sergio Costas's avatar Sergio Costas

Now doesn't allow to use autoincrement or autodecrement with managed pointers

parent ff2e0f4a
......@@ -939,13 +939,30 @@ class crust(object):
if ((statement.type == "INC_OP") or
(statement.type == "DEC_OP")):
if statement.child1 is None:
child = statement.child2
else:
child = statement.child1
vardata = self._find_variable(thread_status, child[0].name, statement.line)
if (self._check_statement_is_crust(child[0], vardata)):
if statement.type == "INC_OP":
self._add_error(thread_status, self.MSG_CRITICAL, "Using autoincrement with __crust__ pointer '{:s}' at line {:d}", child[0].name, statement.line)
else:
self._add_error(thread_status, self.MSG_CRITICAL, "Using autodecrement with __crust__ pointer '{:s}' at line {:d}", child[0].name, statement.line)
return self._eval_statement(child[0], thread_status, first)
tmp1 = statement.copy()
if tmp1.child1 is None:
tmp1.child1 = tmp1.child2
tmp1.child2 = None
tmp1.type = "="
tmp2 = statement.copy()
if statement.type == "INC_OP":
tmp2.type = "+"
elif statement.type == "DEC_OP":
tmp2.type = "-"
if tmp2.child1 is None:
tmp2.child1 = tmp2.child2
tmp3 = statement.copy()
tmp3.type = "CONSTANT"
tmp3.t_null = False
......
......@@ -952,6 +952,10 @@ class Test(unittest.TestCase):
def test226TestNotOverrideSignature2(self):
self._generic_test("unitest/test226.c", [ (crust.crust.MSG_CRITICAL, "Function definition for '{:s}' at line {:d}, file '{:s}' differs from definition at line {:d}, file '{:s}'", "test_function", 4, "unitest/test226.c", 3, "unitest/test226.c") ])
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) ])
if __name__ == '__main__':
try:
os.remove("error_list.txt")
......
typedef __crust__ unsigned char *crust_t;
crust_t main(crust_t param) {
crust_t param2;
param2 = ++param;
param2--;
int a = 5;
a++;
return param2;
}
......@@ -2,7 +2,7 @@ typedef __crust__ unsigned char *crust_t;
int function(crust_t);
void main {
void main() {
crust_t param4;
int retval = function(param4); // ERROR: param4 is used before being assigned
}
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