Skip to contentSkip to conversation

checkpatch: fix uninitialized return value in raw_line subroutine

PATCH In review Dwaipayan Ray 1 participant 2 messages Apr 25, 2021 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 checkpatch: fix uninitialized return value in raw_line subroutine

In case the second argument to raw_line subroutine is 0, $line remains uninitialized and is returned back to the caller. If the caller then tries to perform string concatenation with that value, checkpatch throws an error:

Use of uninitialized value in concatenation (.) or string at ./scripts/checkpatch.pl line 1960.

Fix it by providing an empty string as the initial value for $line.

---

Changes in v2:
- Change commit message

 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 23697a6b1eaa..a98217360375 100755
@@ -1943,7 +1943,7 @@ sub raw_line {
 	my $offset = $linenr - 1;
 	$cnt++;
 
-	my $line;
+	my $line = "";
 	while ($cnt) {
 		$line = $rawlines[$offset++];
 		next if (defined($line) && $line =~ /^-/);
Signature · 1 line
2.30.0
#1 lore raw
Quoted 6 lines · Dwaipayan Ray

In case the second argument to raw_line subroutine is 0, $line remains uninitialized and is returned back to the caller. If the caller then tries to perform string concatenation with that value, checkpatch throws an error:

Quoted 6 lines

Use of uninitialized value in concatenation (.) or string at ./scripts/checkpatch.pl line 1960.

Fix it by providing an empty string as the initial value for $line.

Please ignore this patch. There was a different problem which caused the error.

The following line triggers the errors:
DEVICE_ATTR(foo, 0777, foo_show, foo_store)
(notice the missing semicolon)

Perl throws the following errors when checkpatch is run on a file containing that line:

Use of uninitialized value in concatenation (.) or string at ./scripts/checkpatch.pl line 1960.
Use of uninitialized value in concatenation (.) or string at ./scripts/checkpatch.pl line 1960.
Use of uninitialized value in concatenation (.) or string at ./scripts/checkpatch.pl line 1960.
Use of uninitialized value in concatenation (.) or string at ./scripts/checkpatch.pl line 1960.
Use of uninitialized value in concatenation (.) or string at ./scripts/checkpatch.pl line 1960.
Use of uninitialized value in concatenation (.) or string at ./scripts/checkpatch.pl line 1960.
Use of uninitialized value in concatenation (.) or string at ./scripts/checkpatch.pl line 1960.
Use of uninitialized value in concatenation (.) or string at ./scripts/checkpatch.pl line 1960.
Use of uninitialized value in concatenation (.) or string at ./scripts/checkpatch.pl line 1960.
Use of uninitialized value in concatenation (.) or string at ./scripts/checkpatch.pl line 1960.

Setting $line to "" in raw_line fixed it. Probably -1 is being sent as the second argument to raw_line which results in the uninitialized thing.

Thanks,
Dwaipayan