1*1f5207b7SJohn Levon /*
2*1f5207b7SJohn Levon * Copyright (C) 2013 Oracle.
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 /*
19*1f5207b7SJohn Levon * A place to add function annotations for common functions.
20*1f5207b7SJohn Levon *
21*1f5207b7SJohn Levon */
22*1f5207b7SJohn Levon
23*1f5207b7SJohn Levon #include "smatch.h"
24*1f5207b7SJohn Levon #include "smatch_extra.h"
25*1f5207b7SJohn Levon
param_caps_return(struct expression * call,void * _arg,struct range_list ** res)26*1f5207b7SJohn Levon static int param_caps_return(struct expression *call, void *_arg, struct range_list **res)
27*1f5207b7SJohn Levon {
28*1f5207b7SJohn Levon int arg = PTR_INT(_arg);
29*1f5207b7SJohn Levon struct expression *expr;
30*1f5207b7SJohn Levon struct range_list *rl;
31*1f5207b7SJohn Levon
32*1f5207b7SJohn Levon expr = get_argument_from_call_expr(call->args, arg);
33*1f5207b7SJohn Levon if (get_implied_rl(expr, &rl) && rl_max(rl).value != 0)
34*1f5207b7SJohn Levon *res = alloc_rl(sval_type_val(rl_type(rl), 0), rl_max(rl));
35*1f5207b7SJohn Levon return 1;
36*1f5207b7SJohn Levon }
37*1f5207b7SJohn Levon
register_annotate(int id)38*1f5207b7SJohn Levon void register_annotate(int id)
39*1f5207b7SJohn Levon {
40*1f5207b7SJohn Levon /*
41*1f5207b7SJohn Levon * Technically snprintf() returns the number of bytes which *would* have
42*1f5207b7SJohn Levon * been printed. I do try caclulating that in check_snprintf(). But
43*1f5207b7SJohn Levon * it probably works better to assume the limitter is accurate.
44*1f5207b7SJohn Levon */
45*1f5207b7SJohn Levon add_implied_return_hook("snprintf", ¶m_caps_return, INT_PTR(1));
46*1f5207b7SJohn Levon
47*1f5207b7SJohn Levon }
48