Skip to contentSkip to conversation

Prevent use of unitialized variable

PATCH In review Fredrik Gustafsson 2 participants 2 messages Mar 3, 2013 – Mar 7, 2013 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Prevent use of unitialized variable

Run checkpatch.pl -f kernel/fork.c in commit ecf02a607bd801e742d7bb35c6e40f7ca15edf03
and checkpatch.pl will try to use an uninitialized variable. This patch fixes that.

---
 scripts/checkpatch.pl |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)
scripts/checkpatch.pl +11 -8
index 4d2c7df..4e34368 100755
@@ -3363,14 +3363,17 @@ sub process {
 
 			my $ms_addr = $2;
 			my $ms_val = $7;
-			my $ms_size = $12;
-
-			if ($ms_size =~ /^(0x|)0$/i) {
-				ERROR("MEMSET",
-				      "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
-			} elsif ($ms_size =~ /^(0x|)1$/i) {
-				WARN("MEMSET",
-				     "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
+
+			if (defined $12) {
+				my $ms_size = $12;
+
+				if ($ms_size =~ /^(0x|)0$/i) {
+					ERROR("MEMSET",
+						  "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
+				} elsif ($ms_size =~ /^(0x|)1$/i) {
+					WARN("MEMSET",
+						 "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
+				}
 			}
 		}
 
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 5 lines · On Mon, 4 Mar 2013 00:42:49 +0100 Fredrik Gustafsson <[email protected]> wrote:

Run checkpatch.pl -f kernel/fork.c in commit ecf02a607bd801e742d7bb35c6e40f7ca15edf03
and checkpatch.pl will try to use an uninitialized variable. This patch fixes that.

This isn't a good description of the problem you're seeing. ecf02a607bd801e7 is a merge commit and I see no perl problems running "perl scripts/checkpatch.pl -f kernel/fork.c" with my setup, so it's pretty mysterious.

It is best to quote the full error output when fixing errors.

That things work OK for me isn't surprising, as these things are quite dependent upon the perl version.

Quoted 27 lines
scripts/checkpatch.pl +11 -8
@@ -3363,14 +3363,17 @@ sub process {
 
 			my $ms_addr = $2;
 			my $ms_val = $7;
-			my $ms_size = $12;
-
-			if ($ms_size =~ /^(0x|)0$/i) {
-				ERROR("MEMSET",
-				      "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
-			} elsif ($ms_size =~ /^(0x|)1$/i) {
-				WARN("MEMSET",
-				     "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
+
+			if (defined $12) {
+				my $ms_size = $12;
+
+				if ($ms_size =~ /^(0x|)0$/i) {
+					ERROR("MEMSET",
+						  "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
+				} elsif ($ms_size =~ /^(0x|)1$/i) {
+					WARN("MEMSET",
+						 "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
+				}
 			}
 		}