linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] checkpatch: fix uninitialized return value in raw_line subroutine
@ 2021-04-25  7:44 Dwaipayan Ray
  2021-04-25  8:00 ` Dwaipayan Ray
  0 siblings, 1 reply; 2+ messages in thread
From: Dwaipayan Ray @ 2021-04-25  7:44 UTC (permalink / raw)
  To: joe; +Cc: linux-kernel, lukas.bulwahn, 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:

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.

Signed-off-by: Dwaipayan Ray <dwaipayanray1@gmail.com>
---

Changes in v2:
- Change commit message

 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 23697a6b1eaa..a98217360375 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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 =~ /^-/);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] checkpatch: fix uninitialized return value in raw_line subroutine
  2021-04-25  7:44 [PATCH v2] checkpatch: fix uninitialized return value in raw_line subroutine Dwaipayan Ray
@ 2021-04-25  8:00 ` Dwaipayan Ray
  0 siblings, 0 replies; 2+ messages in thread
From: Dwaipayan Ray @ 2021-04-25  8:00 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-kernel, Lukas Bulwahn

On Sun, Apr 25, 2021 at 1:14 PM Dwaipayan Ray <dwaipayanray1@gmail.com> wrote:
>
> 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.
>

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-25  8:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-25  7:44 [PATCH v2] checkpatch: fix uninitialized return value in raw_line subroutine Dwaipayan Ray
2021-04-25  8:00 ` Dwaipayan Ray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).