ranges: initialize the pointer in get_value_ranges()
[smatch.git] / check_freeing_null.c
bloba2bbb157887a7efad01147faa8664c55ca92aca5
1 /*
2 * sparse/check_freeing_null.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 static void match_free(const char *fn, struct expression *expr, void *data)
16 struct expression *arg_expr;
17 char *name;
18 long long val;
20 arg_expr = get_argument_from_call_expr(expr->args, 0);
21 if (!get_implied_value(arg_expr, &val))
22 return;
23 if (val != 0)
24 return;
25 name = get_variable_from_expr(arg_expr, NULL);
26 sm_msg("warn: calling %s() when '%s' is always NULL.", fn, name);
27 free_string(name);
30 void check_freeing_null(int id)
32 my_id = id;
33 if (!option_spammy)
34 return;
35 if (option_project == PROJ_KERNEL)
36 add_function_hook("kfree", &match_free, NULL);
37 else
38 add_function_hook("free", &match_free, NULL);