sval: update check_deref.c
[smatch.git] / check_return_negative_var.c
blobc4b2b1567c5e4cb099a2293f5e9773a5662b05c9
1 /*
2 * smatch/check_return.c
4 * Copyright (C) 2011 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
11 #include "smatch_slist.h"
13 static int my_id;
15 static void match_return(struct expression *ret_value)
17 struct expression *expr;
18 char *macro;
20 if (!ret_value)
21 return;
22 expr = ret_value;
23 if (ret_value->type != EXPR_PREOP || ret_value->op != '-')
24 return;
26 macro = get_macro_name(expr->unop->pos);
27 if (macro && !strcmp(macro, "PTR_ERR")) {
28 sm_msg("warn: returning -%s()", macro);
29 return;
32 if (!option_spammy)
33 return;
35 expr = get_assigned_expr(ret_value->unop);
36 if (!expr)
37 return;
38 if (expr->type != EXPR_CALL)
39 return;
41 sm_msg("warn: should this return really be negated?");
44 void check_return_negative_var(int id)
46 if (option_project != PROJ_KERNEL)
47 return;
49 my_id = id;
50 add_hook(&match_return, RETURN_HOOK);