smdb_param_buf_size.sh: ask db what size buffers are passed to a function
[smatch.git] / check_min_t.c
blob39d165851264a9aba668fc1341e004075531dde7
1 /*
2 * smatch/check_min_t.c
4 * Copyright (C) 2011 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_assign(struct expression *expr)
16 const char *macro;
17 long long max_left;
18 long long max_right;
19 char *name;
21 if (expr->op != '=')
22 return;
24 macro = get_macro_name(expr->pos);
25 if (!macro)
26 return;
27 if (strcmp(macro, "min_t"))
28 return;
30 if (!get_absolute_max(expr->left, &max_left))
31 return;
32 if (!get_absolute_max(expr->right, &max_right))
33 return;
35 if (max_left >= max_right)
36 return;
38 name = get_variable_from_expr_complex(expr->right, NULL);
39 sm_msg("warn: min_t truncates here '%s' (%lld vs %lld)", name, max_left, max_right);
40 free_string(name);
43 void check_min_t(int id)
45 my_id = id;
46 if (option_project != PROJ_KERNEL)
47 return;
48 add_hook(&match_assign, ASSIGNMENT_HOOK);