2 * sparse/check_deref_check.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_extra.h"
13 extern struct expression_list
*big_expression_stack
;
20 static void underef(const char *name
, struct symbol
*sym
, struct expression
*expr
, void *unused
)
22 set_state(my_id
, name
, sym
, &oktocheck
);
25 static int is_not_really_dereference()
27 struct expression
*tmp
;
31 FOR_EACH_PTR_REVERSE(big_expression_stack
, tmp
) {
36 if (tmp
->op
== '.' && !dot_ops
++)
41 } END_FOR_EACH_PTR_REVERSE(tmp
);
45 static void match_dereference(struct expression
*expr
)
49 if (expr
->type
!= EXPR_PREOP
)
51 if (is_not_really_dereference())
54 expr
= strip_expr(expr
->unop
);
55 if (implied_not_equal(expr
, 0))
57 set_state_expr(my_id
, expr
, &derefed
);
58 name
= get_variable_from_expr(expr
, NULL
);
61 add_modification_hook(name
, &underef
, NULL
);
65 static void match_condition(struct expression
*expr
)
67 if (get_state_expr(my_id
, expr
) == &derefed
) {
70 name
= get_variable_from_expr(expr
, NULL
);
71 if (!implied_not_equal(expr
, 0))
72 sm_msg("warn: variable dereferenced before check '%s'", name
);
73 set_state_expr(my_id
, expr
, &oktocheck
);
78 void check_deref_check(int id
)
81 set_default_state(my_id
, &oktocheck
);
82 add_hook(&match_dereference
, DEREF_HOOK
);
83 add_hook(&match_condition
, CONDITION_HOOK
);