kernel: fix a type bug handling err_cast()
[smatch.git] / check_cmn_err.c
blob1063efeb47749e826cc1d096feef1879026bdaf2
1 /*
2 * Copyright (C) 2016 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
17 * Copyright 2019 Joyent, Inc.
21 * Heavily borrowed from check_wine.c: what we're doing here is teaching smatch
22 * that cmn_err(CE_PANIC, ...) is noreturn.
25 #include "scope.h"
26 #include "smatch.h"
27 #include "smatch_extra.h"
29 #define CE_PANIC (3)
31 void match_cmn_err(const char *fn, struct expression *expr,
32 void *unused)
34 struct expression *arg;
35 sval_t sval;
37 arg = get_argument_from_call_expr(expr->args, 0);
38 if (!get_implied_value(arg, &sval))
39 return;
41 if (sval.value == CE_PANIC)
42 nullify_path();
46 void check_cmn_err(int id)
48 if (option_project != PROJ_ILLUMOS_KERNEL)
49 return;
51 add_function_hook("cmn_err", &match_cmn_err, NULL);