mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-25 02:47:54 -04:00
new: dev: 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. Merge branch 'colin/cocci-detect-iscresult-int-implicit-casts' into 'main' See merge request isc-projects/bind9!11095
This commit is contained in:
commit
2affdbce19
3 changed files with 58 additions and 2 deletions
|
|
@ -1594,7 +1594,7 @@ plus_option(char *option, struct query *query, bool global) {
|
|||
FULLCHECK("yaml");
|
||||
yaml = state;
|
||||
if (state) {
|
||||
display_rrcomments = state;
|
||||
display_rrcomments = 1;
|
||||
}
|
||||
break;
|
||||
case 'z': /* zflag */
|
||||
|
|
|
|||
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)
|
||||
|
|
@ -23,7 +23,7 @@ run_spatch() {
|
|||
echo "Applying semantic patch $spatch..."
|
||||
spatch --jobs "${TEST_PARALLEL_JOBS:-1}" --sp-file "$spatch" --use-gitgrep --dir "." --include-headers $spatchargs >>"$patch" 2>cocci.stderr
|
||||
cat cocci.stderr
|
||||
if grep -q -e "parse error" -e "EXN: Failure" cocci.stderr; then
|
||||
if grep -q -e "parse error" -e "EXN: Failure" -e "WARNING" cocci.stderr; then
|
||||
ret=1
|
||||
fi
|
||||
if [ "$(wc <"$patch" -l)" -gt "0" ]; then
|
||||
|
|
|
|||
Loading…
Reference in a new issue