11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16 */
17
18 /*
19 * Complains about places that return -1 instead of -ENOMEM
20 */
21
22 #include "smatch.h"
23
24 static int my_id;
25
26 static void match_return(struct expression *ret_value)
27 {
28 struct symbol *func_type = get_real_base_type(cur_func_sym);
29 sval_t sval;
30
31 if (!func_type)
32 return;
33 if (!type_unsigned(func_type))
34 return;
35 if (type_bits(func_type) > 16)
36 return;
37 if (!get_fuzzy_min(ret_value, &sval))
38 return;
39 if (sval_is_positive(sval) || sval_cmp_val(sval, -1) == 0)
40 return;
41
42 sm_warning("signedness bug returning '%s'", sval_to_str(sval));
43 }
44
45 void check_return_cast(int id)
46 {
47 my_id = id;
48 add_hook(&match_return, RETURN_HOOK);
49 }
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16 */
17
18 /*
19 * Complains about places that return -1 instead of -ENOMEM
20 */
21
22 #include "smatch.h"
23
24 static int my_id;
25
26 static void match_return(struct expression *ret_value)
27 {
28 struct symbol *func_type = get_real_base_type(cur_func_sym);
29 sval_t sval;
30
31 if (!func_type || func_type->type != SYM_FN)
32 return;
33 func_type = get_real_base_type(func_type);
34 if (!func_type)
35 return;
36 if (!type_unsigned(func_type))
37 return;
38 if (type_bits(func_type) > 16)
39 return;
40 if (!get_fuzzy_min(ret_value, &sval))
41 return;
42 if (sval_is_positive(sval) || sval_cmp_val(sval, -1) == 0)
43 return;
44
45 sm_warning("signedness bug returning '%s'", sval_to_str(sval));
46 }
47
48 void check_return_cast(int id)
49 {
50 my_id = id;
51 add_hook(&match_return, RETURN_HOOK);
52 }
|