Perl/Lint/Policy/InputOutput/RequireCheckedSyscalls.pm

filter: Statementstmt 49.6% 73 / 147 Branchbran 24.5% 27 / 110 Conditioncond 9.0% 6 / 66 MC/DCmcdc 2.7% 1 / 36 Subroutinesub 71.4% 10 / 14 Podpod 0.0% 0 / 1 totaltotal 31.2% 117 / 374 CC 78 SCAR 76.4
CC
78
Cov
33%
evaluate
2427.2
__ANON__
2.0
__ANON__
2.0
CRAP 2080.6
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitCommaSeparatedStatements.pm ↑ Summary Perl/Lint/Policy/RegularExpressions/RequireExtendedFormatting.pm »
1 package Perl::Lint::Policy::InputOutput::RequireCheckedSyscalls;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use List::Util qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Perl::Lint::Constants::Kind;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use B::Keywords;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 DESC => 'Return value of flagged function ignored',
12 EXPL => [208, 278],
13 3 };
14  
15 2 ▶sub evaluate {
Subroutine evaluate: called CC=78 SCAR=77.9
Pod undocumented
16 2 my ($class, $file, $tokens, $src, $args) = @_;
17  
18 2 my $is_target_all = 0;
19 2 my @target_functions = qw/open close say/;
20 2 my $allowed_functions;
21 2 ▶ if (my $required_checked_syscalls_arg = $args->{require_checked_syscalls}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $required_checked_syscalls_arg = $args->{"require_checked_syscalls"}) 0 2 2
22 0 ▶ if (my $functions = $required_checked_syscalls_arg->{functions}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $functions = $required_checked_syscalls_arg->{"functions"}) 0 0 0
23 0 ▶ if ($functions eq ':builtins') {
Branch: 2 branches
BranchTrueFalseTotal
if ($functions eq ':builtins') { } 0 0 0
elsif ($functions eq ':all') { } 0 0 0
24 0 @target_functions = @B::Keywords::Functions;
25 }
26 elsif ($functions eq ':all') {
27 0 $is_target_all = 1;
28 }
29 else {
30 0 @target_functions = ($functions);
31 }
32 }
33  
34 0 ▶ if ($allowed_functions = $required_checked_syscalls_arg->{exclude_functions}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allowed_functions = $required_checked_syscalls_arg->{"exclude_functions"}) 0 0 0
35 0 @target_functions = grep {$_ ne $allowed_functions} @target_functions;
36 }
37 }
38  
39 2 my $is_in_assign_context = 0;
40 2 my $is_in_statement_context = 0;
41 2 my $is_called_syscalls_in_void = 0;
42 2 my $is_enabled_autodie = 0;
43 2 my @violations;
44 2 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 49 2 51
45 49 my $token_type = $token->{type};
46 49 my $token_kind = $token->{kind};
47 49 my $token_data = $token->{data};
48  
49 49 ▶ if ($token_type == ASSIGN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 65) 1 48 49
50 1 $is_in_assign_context = 1;
51 1 next;
52 }
53  
54 48 ▶ if ($token_type == USED_NAME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 94) 8 40 48
55 8 ▶ if ($token_data eq 'Fatal') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_data eq 'Fatal') { } 0 8 8
elsif ($token_data eq 'autodie') { } 0 8 8
56 0 my $next_token = $tokens->[$i+1];
57 0 my $next_token_type = $next_token->{type};
58 0 my $next_token_data = $next_token->{data};
59 0 ▶ if ($next_token_type == REG_LIST) {
Branch: 3 branches
BranchTrueFalseTotal
if ($next_token_type == 147) { } 0 0 0
elsif ($next_token_type == 107) { } 0 0 0
elsif ($next_token_type == 172 || $next_token_type == 173 and &any(sub { $_ eq $next_token_data; } , @target_functions)) { } 0 0 0
60 0 ▶ for ($i += 3; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
61 0 my $token_type = $token->{type};
62 0 my $token_data = $token->{data};
63 0 ▶ if ($token_type == REG_EXP) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 187) { } 0 0 0
elsif ($token_type == 151) { } 0 0 0
64 0 @target_functions = grep {$_ ne $token_data} @target_functions
65 }
66 elsif ($token_type == REG_DELIM) {
67 0 last;
68 }
69 }
70 }
71 elsif ($next_token_type == LEFT_PAREN) {
72 0 my $left_paren_num = 1;
73 0 ▶ for ($i += 2; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
74 0 my $token_type = $token->{type};
75 0 my $token_data = $token->{data};
76 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 172 || $token_type == 173 and &any(sub { $_ eq $token_data; } , @target_functions)) { } 0 0 0
77 0 $left_paren_num++;
78 }
79 0 ▶ elsif (($token_type == STRING || $token_type == RAW_STRING) && any {$_ eq $token_data} @target_functions) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/6
$token_type == 172 || $token_type == 173 and &any(sub { $_ eq $token_data; } , @target_functions)
!ll&&!rl&&r
000
$token_type == 172 or $token_type == 173
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 172 || $token_type == 173 and &any(sub { $_ eq $token_data; } , @target_functions)
$token_type == 172 $token_type == 173 &any(sub { $_ eq $token_data; } , @target_functions)
Truth table0%0/5
A or B and C
A= $token_type == 172B= $token_type == 173C= &any(sub { $_ eq $token_data; } , @target_functions)
ABCresult
00X0
1X00
0100
1X11
0111
80 0 return [];
81 }
82 else {
83 0 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 0 0 0
84 }
85 }
86 }
87 0 ▶ elsif (($next_token_type == STRING || $next_token_type == RAW_STRING) && any {$_ eq $next_token_data} @target_functions) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/6
$next_token_type == 172 || $next_token_type == 173 and &any(sub { $_ eq $next_token_data; } , @target_functions)
!ll&&!rl&&r
000
$next_token_type == 172 or $next_token_type == 173
l!l&&r!l&&!r
000
MC/DC0%0/3
$next_token_type == 172 || $next_token_type == 173 and &any(sub { $_ eq $next_token_data; } , @target_functions)
$next_token_type == 172 $next_token_type == 173 &any(sub { $_ eq $next_token_data; } , @target_functions)
Truth table0%0/5
A or B and C
A= $next_token_type == 172B= $next_token_type == 173C= &any(sub { $_ eq $next_token_data; } , @target_functions)
ABCresult
00X0
1X00
0100
1X11
0111
88 0 last;
89 }
90 }
91 elsif ($token_data eq 'autodie') {
92 0 ▶ if ($tokens->[$i+1]->{type} == REG_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$i + 1]{'type'} == 147) { } 0 0 0
93 0 ▶ for ($i += 3; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
94 0 my $token_type = $token->{type};
95 0 ▶ if ($token_type == REG_EXP && $token->{data} =~ /\A\s*:io\s*\Z/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 187 and $token->{'data'} =~ /\A\s*:io\s*\Z/) { } 0 0 0
elsif ($token_type == 151) { } 0 0 0
Condition0%0/3
$token_type == 187 and $token->{"data"} =~ /\A\s*:io\s*\Z/
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 187 and $token->{"data"} =~ /\A\s*:io\s*\Z/
$token_type == 187 $token->{"data"} =~ /\A\s*:io\s*\Z/
Truth table0%0/3
A and B
A= $token_type == 187B= $token->{"data"} =~ /\A\s*:io\s*\Z/
ABresult
0X0
100
111
96 0 $is_enabled_autodie = 1;
97 }
98 elsif ($token_type == REG_DELIM) {
99 0 last;
100 }
101 }
102 }
103 else {
104 0 $is_enabled_autodie = 1;
105 }
106 }
107  
108 8 next;
109 }
110  
111 40 ▶ if ($token_type == NAMESPACE && $token_data eq 'Fatal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 127 and $token_data eq "Fatal") 0 40 40
Condition33%1/3
$token_type == 127 and $token_data eq "Fatal"
!ll&&!rl&&r
4000
MC/DC0%0/2
$token_type == 127 and $token_data eq "Fatal"
$token_type == 127 $token_data eq "Fatal"
Truth table33%1/3
A and B
A= $token_type == 127B= $token_data eq "Fatal"
ABresult
0X0
100
111
112 0 my $skipped_token = $tokens->[$i+2];
113 0 ▶ if ($skipped_token && $skipped_token->{type} == NAMESPACE && $skipped_token->{data} eq 'Exception') {
Branch: 1 branch
BranchTrueFalseTotal
if ($skipped_token and $skipped_token->{"type"} == 127 and $skipped_token->{"data"} eq "Exception") 0 0 0
Condition0%0/6
$skipped_token and $skipped_token->{"type"} == 127 and $skipped_token->{"data"} eq "Exception"
!ll&&!rl&&r
000
$skipped_token and $skipped_token->{"type"} == 127
!ll&&!rl&&r
000
MC/DC0%0/3
$skipped_token and $skipped_token->{"type"} == 127 and $skipped_token->{"data"} eq "Exception"
$skipped_token $skipped_token->{"type"} == 127 $skipped_token->{"data"} eq "Exception"
Truth table0%0/4
A and B and C
A= $skipped_tokenB= $skipped_token->{"type"} == 127C= $skipped_token->{"data"} eq "Exception"
ABCresult
0XX0
10X0
1100
1111
114 0 ▶ for ($i += 3; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
115 0 my $token_type = $token->{type};
116 0 my $token_data = $token->{data};
117 0 ▶ if ($token_type == REG_LIST) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token_type == 147) { } 0 0 0
elsif ($token_type == 107) { } 0 0 0
elsif ($token_type == 172 || $token_type == 173 and &any(sub { $_ eq $token_data; } , @target_functions)) { } 0 0 0
elsif ($token->{'kind'} == 21) { } 0 0 0
118 0 ▶ for ($i += 2; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
119 0 my $token_type = $token->{type};
120 0 my $token_data = $token->{data};
121 0 ▶ if ($token_type == REG_EXP) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 187) { } 0 0 0
elsif ($token_type == 151) { } 0 0 0
122 0 @target_functions = grep {$_ ne $token_data} @target_functions
123 }
124 elsif ($token_type == REG_DELIM) {
125 0 last;
126 }
127 }
128 }
129 elsif ($token_type == LEFT_PAREN) {
130 0 my $left_paren_num = 1;
131 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
132 0 my $token_type = $token->{type};
133 0 my $token_data = $token->{data};
134 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 172 || $token_type == 173 and &any(sub { $_ eq $token_data; } , @target_functions)) { } 0 0 0
135 0 $left_paren_num++;
136 }
137 0 ▶ elsif (($token_type == STRING || $token_type == RAW_STRING) && any {$_ eq $token_data} @target_functions) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/6
$token_type == 172 || $token_type == 173 and &any(sub { $_ eq $token_data; } , @target_functions)
!ll&&!rl&&r
000
$token_type == 172 or $token_type == 173
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 172 || $token_type == 173 and &any(sub { $_ eq $token_data; } , @target_functions)
$token_type == 172 $token_type == 173 &any(sub { $_ eq $token_data; } , @target_functions)
Truth table0%0/5
A or B and C
A= $token_type == 172B= $token_type == 173C= &any(sub { $_ eq $token_data; } , @target_functions)
ABCresult
00X0
1X00
0100
1X11
0111
138 0 return [];
139 }
140 else {
141 0 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 0 0 0
142 }
143 }
144 }
145 0 ▶ elsif (($token_type == STRING || $token_type == RAW_STRING) && any {$_ eq $token_data} @target_functions) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/6
$token_type == 172 || $token_type == 173 and &any(sub { $_ eq $token_data; } , @target_functions)
!ll&&!rl&&r
000
$token_type == 172 or $token_type == 173
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 172 || $token_type == 173 and &any(sub { $_ eq $token_data; } , @target_functions)
$token_type == 172 $token_type == 173 &any(sub { $_ eq $token_data; } , @target_functions)
Truth table0%0/5
A or B and C
A= $token_type == 172B= $token_type == 173C= &any(sub { $_ eq $token_data; } , @target_functions)
ABCresult
00X0
1X00
0100
1X11
0111
146 0 last;
147 }
148 elsif ($token->{kind} == KIND_STMT_END) {
149 0 last;
150 }
151 }
152 }
153  
154 0 next;
155 }
156  
157 40 ▶ if ($token_kind == KIND_STMT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_kind == 17) 1 39 40
158 1 $is_in_statement_context = 1;
159  
160 1 ▶ if ($tokens->[$i+1]->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$i + 1]{"type"} == 107) 1 0 1
161 1 $i++;
162 1 my $left_paren_num = 1;
163 1 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 1 0 1
164 1 my $token_type = $token->{type};
165 1 ▶ if ($token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 107) { } 0 1 1
166 0 $left_paren_num++;
167 }
168 else {
169 1 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 1 0 1
170 }
171 }
172 }
173 1 next;
174 }
175  
176 39 ▶ if ($token_type == BUILTIN_FUNC || ($is_target_all && $token_type == RETURN)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70 or $is_target_all and $token_type == 0) 1 38 39
Condition50%3/6
$token_type == 70 or $is_target_all and $token_type == 0
l!l&&r!l&&!r
1038
$is_target_all and $token_type == 0
!ll&&!rl&&r
3800
MC/DC33%1/3
$token_type == 70 or $is_target_all and $token_type == 0
$token_type == 70 $is_target_all $token_type == 0
Truth table50%2/4
A or B and C
A= $token_type == 70B= $is_target_allC= $token_type == 0
ABCresult
1XX1
0111
00X0
0100
177 1 ▶ if ($is_target_all || any {$_ eq $token_data} @target_functions) {
Subroutine __ANON__: called CC=1 SCAR=0.8
Branch: 2 branches
BranchTrueFalseTotal
if ($is_target_all or &any(sub { $_ eq $token_data; } , @target_functions)) { } 0 1 1
elsif ($token_data eq 'no') { } 0 1 1
Condition33%1/3
$is_target_all or &any(sub { $_ eq $token_data; } , @target_functions)
l!l&&r!l&&!r
001
MC/DC0%0/2
$is_target_all or &any(sub { $_ eq $token_data; } , @target_functions)
$is_target_all &any(sub { $_ eq $token_data; } , @target_functions)
Truth table33%1/3
A or B
A= $is_target_allB= &any(sub { $_ eq $token_data; } , @target_functions)
ABresult
1X1
011
000
178 0 ▶ if (!$is_in_assign_context && !$is_in_statement_context) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_in_assign_context or $is_in_statement_context) 0 0 0
Condition0%0/3
$is_in_assign_context or $is_in_statement_context
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_in_assign_context or $is_in_statement_context
$is_in_assign_context $is_in_statement_context
Truth table0%0/3
A or B
A= $is_in_assign_contextB= $is_in_statement_context
ABresult
1X1
011
000
179 0 $is_called_syscalls_in_void = 1;
180 }
181 }
182 elsif ($token_data eq 'no') {
183 0 my $next_token = $tokens->[++$i];
184 0 ▶ if ($next_token->{type} == KEY && $next_token->{data} eq 'autodie') {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token->{"type"} == 122 and $next_token->{"data"} eq "autodie") 0 0 0
Condition0%0/3
$next_token->{"type"} == 122 and $next_token->{"data"} eq "autodie"
!ll&&!rl&&r
000
MC/DC0%0/2
$next_token->{"type"} == 122 and $next_token->{"data"} eq "autodie"
$next_token->{"type"} == 122 $next_token->{"data"} eq "autodie"
Truth table0%0/3
A and B
A= $next_token->{"type"} == 122B= $next_token->{"data"} eq "autodie"
ABresult
0X0
100
111
185 0 $is_enabled_autodie = 0;
186 }
187 }
188 1 next;
189 }
190  
191 38 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($is_target_all and $token_type == 204 || $token_type == 122 && $$tokens[++$i]{"type"} == 107) 0 38 38
Condition11%1/9
$is_target_all and $token_type == 204 || $token_type == 122 && $$tokens[++$i]{"type"} == 107
!ll&&!rl&&r
3800
$token_type == 204 or $token_type == 122 and $$tokens[++$i]{"type"} == 107
l!l&&r!l&&!r
000
$token_type == 122 and $$tokens[++$i]{"type"} == 107
!ll&&!rl&&r
000
MC/DC0%0/4
$is_target_all and $token_type == 204 || $token_type == 122 && $$tokens[++$i]{"type"} == 107
$is_target_all $token_type == 204 $token_type == 122 $$tokens[++$i]{"type"} == 107
Truth table20%1/5
A and B or C and D
A= $is_target_allB= $token_type == 204C= $token_type == 122D= $$tokens[++$i]{"type"} == 107
ABCDresult
0XXX0
100X0
10100
11XX1
10111
192 $is_target_all &&
193 ($token_type == CALL || ($token_type == KEY && $tokens->[++$i]->{type} == LEFT_PAREN))
194 ) {
195 0 ▶ if ($allowed_functions && $token_data =~ /\A$allowed_functions\s*\(?/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($allowed_functions and $token_data =~ /\A$allowed_functions\s*\(?/) { } 0 0 0
elsif (not $is_in_assign_context || $is_in_statement_context) { } 0 0 0
Condition0%0/3
$allowed_functions and $token_data =~ /\A$allowed_functions\s*\(?/
!ll&&!rl&&r
000
MC/DC0%0/2
$allowed_functions and $token_data =~ /\A$allowed_functions\s*\(?/
$allowed_functions $token_data =~ /\A$allowed_functions\s*\(?/
Truth table0%0/3
A and B
A= $allowed_functionsB= $token_data =~ /\A$allowed_functions\s*\(?/
ABresult
0X0
100
111
196 0 next;
197 }
198 ▶ elsif (!$is_in_assign_context && !$is_in_statement_context) {
Condition0%0/3
$is_in_assign_context || $is_in_statement_context
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_in_assign_context || $is_in_statement_context
$is_in_assign_context $is_in_statement_context
Truth table0%0/3
A || B
A= $is_in_assign_contextB= $is_in_statement_context
ABresult
1X1
011
000
199 0 $is_called_syscalls_in_void = 1;
200 }
201 0 next;
202 }
203  
204 38 ▶ if ($token_kind == KIND_OP) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_kind == 1) 2 36 38
205 2 $is_in_statement_context = 1;
206 2 $is_called_syscalls_in_void = 0;
207 2 next;
208 }
209  
210 36 ▶ if ($token_kind == KIND_STMT_END) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_kind == 21) 11 25 36
211 11 ▶ next if $is_enabled_autodie;
Branch: 1 branch
BranchTrueFalseTotal
if $is_enabled_autodie 0 11 11
212  
213 11 ▶ if ($is_called_syscalls_in_void) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_called_syscalls_in_void) 0 11 11
214 push @violations, {
215 filename => $file,
216 line => $token->{line},
217 0 description => DESC,
218 explanation => EXPL,
219 policy => __PACKAGE__,
220 };
221 }
222  
223 11 $is_in_assign_context = 0;
224 11 $is_in_statement_context = 0;
225 11 $is_called_syscalls_in_void = 0;
226 11 next;
227 }
228  
229 }
230  
231 2 return \@violations;
232 }
233  
234 3 1;
235  
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitCommaSeparatedStatements.pm ↑ Summary Perl/Lint/Policy/RegularExpressions/RequireExtendedFormatting.pm »