1*1f5207b7SJohn Levon /* 2*1f5207b7SJohn Levon * Copyright (C) 2010 Dan Carpenter. 3*1f5207b7SJohn Levon * 4*1f5207b7SJohn Levon * This program is free software; you can redistribute it and/or 5*1f5207b7SJohn Levon * modify it under the terms of the GNU General Public License 6*1f5207b7SJohn Levon * as published by the Free Software Foundation; either version 2 7*1f5207b7SJohn Levon * of the License, or (at your option) any later version. 8*1f5207b7SJohn Levon * 9*1f5207b7SJohn Levon * This program is distributed in the hope that it will be useful, 10*1f5207b7SJohn Levon * but WITHOUT ANY WARRANTY; without even the implied warranty of 11*1f5207b7SJohn Levon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*1f5207b7SJohn Levon * GNU General Public License for more details. 13*1f5207b7SJohn Levon * 14*1f5207b7SJohn Levon * You should have received a copy of the GNU General Public License 15*1f5207b7SJohn Levon * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt 16*1f5207b7SJohn Levon */ 17*1f5207b7SJohn Levon 18*1f5207b7SJohn Levon #include "smatch.h" 19*1f5207b7SJohn Levon 20*1f5207b7SJohn Levon static void db_returns_buf_size(struct expression *expr, int param, char *unused, char *math) 21*1f5207b7SJohn Levon { 22*1f5207b7SJohn Levon struct expression *call; 23*1f5207b7SJohn Levon struct symbol *left_type, *right_type; 24*1f5207b7SJohn Levon int bytes; 25*1f5207b7SJohn Levon sval_t sval; 26*1f5207b7SJohn Levon 27*1f5207b7SJohn Levon if (expr->type != EXPR_ASSIGNMENT) 28*1f5207b7SJohn Levon return; 29*1f5207b7SJohn Levon right_type = get_pointer_type(expr->right); 30*1f5207b7SJohn Levon if (!right_type || type_bits(right_type) != -1) 31*1f5207b7SJohn Levon return; 32*1f5207b7SJohn Levon 33*1f5207b7SJohn Levon call = strip_expr(expr->right); 34*1f5207b7SJohn Levon left_type = get_pointer_type(expr->left); 35*1f5207b7SJohn Levon 36*1f5207b7SJohn Levon if (!parse_call_math(call, math, &sval) || sval.value == 0) 37*1f5207b7SJohn Levon return; 38*1f5207b7SJohn Levon if (!left_type) 39*1f5207b7SJohn Levon return; 40*1f5207b7SJohn Levon bytes = type_bytes(left_type); 41*1f5207b7SJohn Levon if (bytes <= 0) 42*1f5207b7SJohn Levon return; 43*1f5207b7SJohn Levon if (sval.uvalue >= bytes) 44*1f5207b7SJohn Levon return; 45*1f5207b7SJohn Levon sm_error("not allocating enough data %d vs %s", bytes, sval_to_str(sval)); 46*1f5207b7SJohn Levon } 47*1f5207b7SJohn Levon 48*1f5207b7SJohn Levon void check_allocating_enough_data(int id) 49*1f5207b7SJohn Levon { 50*1f5207b7SJohn Levon select_return_states_hook(BUF_SIZE, &db_returns_buf_size); 51*1f5207b7SJohn Levon } 52