2 * sparse/check_initializer_deref.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
17 static void underef(const char *name
, struct symbol
*sym
, struct expression
*expr
, void *unused
)
19 set_state(name
, my_id
, sym
, &oktocheck
);
22 static void record_dereferenced_vars(struct expression
*expr
)
27 if (!expr
|| expr
->type
!= EXPR_DEREF
)
32 if (!strcmp(show_special(expr
->op
), "*")) {
33 name
= get_variable_from_expr(expr
->unop
, &sym
);
35 set_state_expr(my_id
, expr
->unop
, &derefed
);
36 add_modification_hook(name
, &underef
, NULL
);
40 record_dereferenced_vars(expr
->unop
);
43 static void match_declarations(struct symbol
*sym
)
45 if (!sym
->initializer
)
47 record_dereferenced_vars(sym
->initializer
);
51 static void match_condition(struct expression
*expr
)
56 expr
= strip_expr(expr
);
57 name
= get_variable_from_expr(expr
, &sym
);
61 if (get_state_expr(my_id
, expr
) == &derefed
) {
62 smatch_msg("warn: variable derefenced in initializer '%s'",
64 set_state_expr(my_id
, expr
, &oktocheck
);
71 void check_initializer_deref(int id
)
74 set_default_state(my_id
, &oktocheck
);
75 add_hook(&match_declarations
, DECLARATION_HOOK
);
76 add_hook(&match_condition
, CONDITION_HOOK
);