mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-10 09:21:57 -04:00
add spatch to detect implicit bool/int/result cast
Detection of implicit cast from a boolean into an int, or an isc_result_t into a boolean (either in an assignement or return position). If such pattern is found, a warning comment is added into the code (and the CI will fails) so the error can be spotted and manually fixed.
This commit is contained in:
parent
fbc9262c39
commit
754595ea2d
1 changed files with 56 additions and 0 deletions
56
cocci/implicit_casts_warning.spatch
Normal file
56
cocci/implicit_casts_warning.spatch
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
@bool_into_int_warning@
|
||||
position p;
|
||||
int i;
|
||||
bool b;
|
||||
@@
|
||||
i = b@p;
|
||||
|
||||
@script:python@
|
||||
p << bool_into_int_warning.p;
|
||||
@@
|
||||
report = coccilib.report.build_report(p[0], "WARNING: implicit bool->int cast on assignment")
|
||||
sys.stderr.write(report)
|
||||
|
||||
|
||||
|
||||
@return_isc_result_t_into_bool_warning@
|
||||
position p;
|
||||
isc_result_t result;
|
||||
identifier fn;
|
||||
identifier literalresult =~ "ISC_R_.*|DNS_R_.*|DST_R_.*|ISCCC_R_.*";
|
||||
@@
|
||||
bool fn(...) {
|
||||
<...
|
||||
(
|
||||
return result@p;
|
||||
|
|
||||
return literalresult@p;
|
||||
)
|
||||
...>
|
||||
}
|
||||
|
||||
@script:python@
|
||||
p << return_isc_result_t_into_bool_warning.p;
|
||||
@@
|
||||
report = coccilib.report.build_report(p[0], "WARNING: implicit isc_result_t->bool cast on return value")
|
||||
sys.stderr.write(report)
|
||||
|
||||
|
||||
|
||||
@isc_result_t_into_bool_warning@
|
||||
position p;
|
||||
isc_result_t result;
|
||||
identifier literalresult =~ "ISC_R_.*|DNS_R_.*|DST_R_.*|ISCCC_R_.*";
|
||||
bool b;
|
||||
@@
|
||||
(
|
||||
b = result@p;
|
||||
|
|
||||
b = literalresult@p;
|
||||
)
|
||||
|
||||
@script:python@
|
||||
p << isc_result_t_into_bool_warning.p;
|
||||
@@
|
||||
report = coccilib.report.build_report(p[0], "WARNING: implicit isc_result_t->bool cast on assignment")
|
||||
sys.stderr.write(report)
|
||||
Loading…
Reference in a new issue