2 * Copyright (C) 2012 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
22 static void match_parameter(const char *fn
, struct expression
*expr
, void *_param
)
24 int param
= PTR_INT(_param
);
25 struct expression
*arg
;
28 arg
= get_argument_from_call_expr(expr
->args
, param
);
29 arg
= strip_expr(arg
);
32 if (arg
->type
!= EXPR_COMPARE
)
35 name
= expr_to_str_sym(arg
, NULL
);
36 sm_warning("expected a buffer size but got a comparison '%s'", name
);
40 static void register_funcs_from_file(void)
48 memset(prev_func
, 0, sizeof(prev_func
));
49 snprintf(name
, 256, "%s.sizeof_param", option_project_str
);
51 token
= get_tokens_file(name
);
54 if (token_type(token
) != TOKEN_STREAMBEGIN
)
57 while (token_type(token
) != TOKEN_STREAMEND
) {
58 if (token_type(token
) != TOKEN_IDENT
)
60 func
= show_ident(token
->ident
);
63 if (token_type(token
) != TOKEN_NUMBER
)
65 size
= atoi(token
->number
);
68 if (token_type(token
) == TOKEN_SPECIAL
) {
69 if (token
->special
!= '-')
73 if (token_type(token
) != TOKEN_NUMBER
)
75 /* we don't care which argument hold the buf pointer */
78 if (strcmp(func
, prev_func
) == 0)
80 strncpy(prev_func
, func
, 255);
82 add_function_hook(func
, &match_parameter
, INT_PTR(size
));
85 if (token_type(token
) != TOKEN_STREAMEND
)
86 sm_perror("problem parsing '%s'", name
);
90 void check_wrong_size_arg(int id
)
93 register_funcs_from_file();