2 * smatch/check_db_info.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_extra.h"
15 static char *show_num(long long num
)
17 static char buff
[256];
20 snprintf(buff
, 255, "(%lld)", num
);
22 snprintf(buff
, 255, "%lld", num
);
28 static char *show_ranges_raw(struct range_list
*list
)
30 struct data_range
*tmp
;
31 static char full
[256];
36 FOR_EACH_PTR(list
, tmp
) {
38 strncat(full
, ",", 254 - strlen(full
));
39 if (tmp
->min
== tmp
->max
) {
40 strncat(full
, show_num(tmp
->min
), 254 - strlen(full
));
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
);
50 static void match_return(struct expression
*ret_value
)
52 struct smatch_state
*state
;
54 struct range_list
*rlist
;
57 sm_msg("info: return_value void");
60 if (get_value(ret_value
, &val
)) {
61 sm_msg("info: return_value %lld", val
);
64 state
= get_state_expr(SMATCH_EXTRA
, ret_value
);
66 sm_msg("info: return_value unknown");
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
)
78 add_hook(&match_return
, RETURN_HOOK
);