function_hooks/unwind: introduce return_implies_exact()
[smatch.git] / smatch_annotate.c
blob21df3d1b72a06a7c1e2caa7db5eded85e7548abf
1 /*
2 * Copyright (C) 2013 Oracle.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
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
19 * A place to add function annotations for common functions.
23 #include "smatch.h"
24 #include "smatch_extra.h"
26 static int param_caps_return(struct expression *call, void *_arg, struct range_list **res)
28 int arg = PTR_INT(_arg);
29 struct expression *expr;
30 struct range_list *rl;
32 expr = get_argument_from_call_expr(call->args, arg);
33 if (get_implied_rl(expr, &rl) && rl_max(rl).value != 0) {
34 *res = alloc_rl(sval_type_val(rl_type(rl), 0), rl_max(rl));
35 return 1;
37 return 0;
40 void register_annotate(int id)
43 * Technically snprintf() returns the number of bytes which *would* have
44 * been printed. I do try caclulating that in check_snprintf(). But
45 * it probably works better to assume the limitter is accurate.
47 add_implied_return_hook("snprintf", &param_caps_return, INT_PTR(1));