11f5207b7SJohn Levon /* 21f5207b7SJohn Levon * Copyright (C) 2012 Oracle. 31f5207b7SJohn Levon * 41f5207b7SJohn Levon * This program is free software; you can redistribute it and/or 51f5207b7SJohn Levon * modify it under the terms of the GNU General Public License 61f5207b7SJohn Levon * as published by the Free Software Foundation; either version 2 71f5207b7SJohn Levon * of the License, or (at your option) any later version. 81f5207b7SJohn Levon * 91f5207b7SJohn Levon * This program is distributed in the hope that it will be useful, 101f5207b7SJohn Levon * but WITHOUT ANY WARRANTY; without even the implied warranty of 111f5207b7SJohn Levon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 121f5207b7SJohn Levon * GNU General Public License for more details. 131f5207b7SJohn Levon * 141f5207b7SJohn Levon * You should have received a copy of the GNU General Public License 151f5207b7SJohn Levon * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt 161f5207b7SJohn Levon */ 171f5207b7SJohn Levon 181f5207b7SJohn Levon /* 191f5207b7SJohn Levon * Complains about places that return -1 instead of -ENOMEM 201f5207b7SJohn Levon */ 211f5207b7SJohn Levon 221f5207b7SJohn Levon #include "smatch.h" 231f5207b7SJohn Levon 241f5207b7SJohn Levon static int my_id; 251f5207b7SJohn Levon match_return(struct expression * ret_value)261f5207b7SJohn Levonstatic void match_return(struct expression *ret_value) 271f5207b7SJohn Levon { 281f5207b7SJohn Levon struct symbol *func_type = get_real_base_type(cur_func_sym); 291f5207b7SJohn Levon sval_t sval; 301f5207b7SJohn Levon 31*efe51d0cSJohn Levon if (!func_type || func_type->type != SYM_FN) 32*efe51d0cSJohn Levon return; 33*efe51d0cSJohn Levon func_type = get_real_base_type(func_type); 341f5207b7SJohn Levon if (!func_type) 351f5207b7SJohn Levon return; 361f5207b7SJohn Levon if (!type_unsigned(func_type)) 371f5207b7SJohn Levon return; 381f5207b7SJohn Levon if (type_bits(func_type) > 16) 391f5207b7SJohn Levon return; 401f5207b7SJohn Levon if (!get_fuzzy_min(ret_value, &sval)) 411f5207b7SJohn Levon return; 421f5207b7SJohn Levon if (sval_is_positive(sval) || sval_cmp_val(sval, -1) == 0) 431f5207b7SJohn Levon return; 441f5207b7SJohn Levon 451f5207b7SJohn Levon sm_warning("signedness bug returning '%s'", sval_to_str(sval)); 461f5207b7SJohn Levon } 471f5207b7SJohn Levon check_return_cast(int id)481f5207b7SJohn Levonvoid check_return_cast(int id) 491f5207b7SJohn Levon { 501f5207b7SJohn Levon my_id = id; 511f5207b7SJohn Levon add_hook(&match_return, RETURN_HOOK); 521f5207b7SJohn Levon } 53