Commit 7287e442 authored by Sergio Costas's avatar Sergio Costas

Now doesn't report uninitialized variable when defining arrays.

parent 119b8e7d
......@@ -1186,11 +1186,40 @@ class crust(object):
thread_status["variables"][0][node.name] = tmpdata
def _create_param(self, thread_status, name, param_type):
pointer = 0
while (param_type[-1] == '*'):
param_type = param_type[:-1]
pointer += 1
param = self._get_variable_properties(thread_status, name, pointer, False)
return param
def _add_builtin_function(self, thread_status, function_name, retval_type, parameters):
tmpparams = self._get_variable_properties(thread_status, None, 0, False)
tmpparams["function"] = True
tmpparams["value"] = crust.VALUE_FUNCTION
tmpparams["function_params"] = [ self._create_param(thread_status, function_name, retval_type) ]
for param in parameters:
tmpparams["function_params"].append(self._create_param(thread_status, "", param))
tmpparams["name"] = function_name
tmpparams["ellipsis"] = False
tmpparams["definition_line"] = -1
tmpparams["definition_file"] = "gcc_builtin"
thread_status["variables"][0][function_name] = tmpparams
def process_tree(self, tree, verbose = False):
""" Process the main tree with the global variables and the function definitions and declarations """
self.verbose = verbose
thread_status = { "variables": [ {} ], "debug_level": 0, "loop_level": 0, "find_label": None, "return_is_crust": False, "return_is_borrowed": False, "return_cant_null": False, "returned_something": None, "current_function": "" }
# Set the GCC builtin functions
self._add_builtin_function(thread_status, "__builtin_bswap32", "uint32_t", ["uint32_t"])
self._add_builtin_function(thread_status, "__builtin_bswap64", "uint64_t", ["uint64_t"])
# First fill all the global variables and the function declarations
for node in tree:
if (node.type == "TYPE_SPECIFIER"):
......@@ -1478,7 +1507,7 @@ class crust(object):
var_defined["enum"] = False
#var_defined = self._node_fill_parameters(thread_status, node, var_defined)
thread_status["variables"][0][node.name] = var_defined
if (node.assignment is None) or (node.t_static):
if (node.assignment is None) or (node.t_static) or (node.arrays is not None):
return self._check_return_block(tree[1:], thread_status)
# if the variable definition also has an assignment, then create a fake '=' node
tmpnode = node.copy()
......@@ -1836,7 +1865,7 @@ def get_parameters():
if (parameter == "-h") or (parameter == "--help"):
print("CRUST {:s}".format(crust.version))
print("Usage:")
print(" crust [-Iinclude_path] [-I...] [-Ddefine] [-D...] [-include filename] [-include...] [--nowarnings] [--nocpp] [--quiet] [-eexclude_filename] file.c [file.c] ...")
print(" crust [-Iinclude_path] [-I...] [-Ddefine] [-D...] [-include filename] [-include...] [--nowarnings] [--nocpp] [--quiet] [-eexclude_filename] [--debug1] [--debug2] file.c [file.c] ...")
print()
print(" -I allows to specify paths where the C preprocessor will search for header files. Can be repeated as many times as paths have to be added")
print(" -D allows to specify #defines from command line that the C preprocessor must consider defined. Can be repeated as many times as defines are needed")
......@@ -1846,6 +1875,7 @@ def get_parameters():
print(" --quiet will not show extra information")
print(" -e allows to specify file names to exclude. This is useful when a filename contains wildcards")
print(" --preprocessed stores the preprocessed code (this is, after being passed through the C PreProcessor) with the specified filename")
print(" --debug1 & --debug2 shows the parsed tree between source code lines specified in both statements")
print(" file.c the path to the file or files to analyze. It can contain wildcards, and it is possible to also specify several files")
print()
sys.exit(0)
......
......@@ -644,7 +644,7 @@ direct_declarator
show_debug(__LINE__, $$, "direct_declarator");
tmpleaf = new_leaf(BRACKETS_CONTAINER,$1);
append_right($$,tmpleaf);
free_tree($2);
$$->arrays = $2;
free_tree($3); }
| direct_declarator '(' parameter_type_list ')' { $$ = $1; // List of parameters in the definition of a function
show_debug(__LINE__, $$, "direct_declarator");
......
......@@ -907,6 +907,12 @@ class Test(unittest.TestCase):
def test211CheckTypedefEnums(self):
self._all_fine_test("unitest/test211.c")
def test212InitializedArrays(self):
self._all_fine_test("unitest/test212.c")
def test213InitializedNoSizeArrays(self):
self._all_fine_test("unitest/test213.c")
if __name__ == '__main__':
try:
os.remove("error_list.txt")
......
void main() {
int v[7] = {0, 0, 0, 0, 0, 0, 0};
v[5] = 4;
}
void main() {
int v[] = {0};
v[5] = 4;
}
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