*new* check_macros: find macro precedence bugs
[smatch.git] / check_db_info.c
blobec63a64591cdc23a0c0b442767d9f4ce7d89b6fd
1 /*
2 * smatch/check_db_info.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
11 #include "smatch_extra.h"
13 static int my_id;
15 static char *show_num(long long num)
17 static char buff[256];
19 if (num < 0) {
20 snprintf(buff, 255, "(%lld)", num);
21 } else {
22 snprintf(buff, 255, "%lld", num);
24 buff[255] = '\0';
25 return buff;
28 static char *show_ranges_raw(struct range_list *list)
30 struct data_range *tmp;
31 static char full[256];
32 int i = 0;
34 full[0] = '\0';
35 full[255] = '\0';
36 FOR_EACH_PTR(list, tmp) {
37 if (i++)
38 strncat(full, ",", 254 - strlen(full));
39 if (tmp->min == tmp->max) {
40 strncat(full, show_num(tmp->min), 254 - strlen(full));
41 continue;
43 strncat(full, show_num(tmp->min), 254 - strlen(full));
44 strncat(full, "-", 254 - strlen(full));
45 strncat(full, show_num(tmp->max), 254 - strlen(full));
46 } END_FOR_EACH_PTR(tmp);
47 return full;
50 static void match_return(struct expression *ret_value)
52 struct smatch_state *state;
53 long long val;
54 struct range_list *rlist;
56 if (!ret_value) {
57 sm_msg("info: return_value void");
58 return;
60 if (get_value(ret_value, &val)) {
61 sm_msg("info: return_value %lld", val);
62 return;
64 state = get_state_expr(SMATCH_EXTRA, ret_value);
65 if (!state) {
66 sm_msg("info: return_value unknown");
67 return;
69 rlist = ((struct data_info *)state->data)->value_ranges;
70 sm_msg("info: return_value %s", show_ranges_raw(rlist));
73 void check_db_info(int id)
75 if (!option_print_returns)
76 return;
77 my_id = id;
78 add_hook(&match_return, RETURN_HOOK);