#include "smatch.h"
#include "smatch_slist.h"
static void check_func_return(struct expression *expr)
{
struct symbol *sym = get_real_base_type(get_type(expr->fn));
const char *func = expr_to_str(expr->fn);
struct statement *stmt;
if (sym == NULL) {
sm_error("unknown type for func '%s'", func);
return;
}
if (expr->type != EXPR_CALL) {
sm_error("func '%s' is not a call site", func);
return;
}
if (strcmp(func, "memcpy") == 0 ||
strcmp(func, "memmove") == 0 ||
strcmp(func, "memset") == 0)
return;
if (strcmp(func, "printf") == 0 || strcmp(func, "vprintf") == 0)
return;
if (strcmp(func, "fprintf") == 0 || strcmp(func, "vfprintf")) {
const char *arg0 = expr_to_str(get_argument_from_call_expr(expr->args, 0));
if (arg0 != NULL &&
(strcmp(arg0, "(&__iob[1])") == 0 ||
strcmp(arg0, "(&__iob[2])") == 0))
return;
}
if (sym == &void_ctype || (sym->type == SYM_FN &&
get_real_base_type(sym) == &void_ctype))
return;
stmt = last_ptr_list((struct ptr_list *)big_statement_stack);
if (stmt && stmt->type == STMT_EXPRESSION && stmt->expression == expr)
sm_error("unchecked function return '%s'", expr_to_str(expr->fn));
}
void check_all_func_returns(int id)
{
if (option_project != PROJ_ILLUMOS_KERNEL &&
option_project != PROJ_ILLUMOS_USER)
return;
add_hook(&check_func_return, FUNCTION_CALL_HOOK);
}