Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 283070
b: refs/heads/master
c: 554e165
h: refs/heads/master
v: v3
  • Loading branch information
Andy Whitcroft authored and Linus Torvalds committed Jan 11, 2012
1 parent 7472d1c commit 91f7006
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f74bd1942e04a0cedd1e9c8b331141e75add49c0
refs/heads/master: 554e165cf32610ec9596a183fa1b54a5707fc3cb
28 changes: 22 additions & 6 deletions trunk/scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3120,6 +3120,28 @@ sub process {
"Avoid line continuations in quoted strings\n" . $herecurr);
}

# Check for misused memsets
if (defined $stat && $stat =~ /\bmemset\s*\((.*)\)/s) {
my $args = $1;

# Flatten any parentheses and braces
while ($args =~ s/\([^\(\)]*\)/10/s ||
$args =~ s/\{[^\{\}]*\}/10/s ||
$args =~ s/\[[^\[\]]*\]/10/s)
{
}
# Extract the simplified arguments.
my ($ms_addr, $ms_val, $ms_size) =
split(/\s*,\s*/, $args);
if ($ms_size =~ /^(0x|)0$/i) {
ERROR("MEMSET",
"memset size is 3rd argument, not the second.\n" . $herecurr);
} elsif ($ms_size =~ /^(0x|)1$/i) {
WARN("MEMSET",
"single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . $herecurr);
}
}

# check for new externs in .c files.
if ($realfile =~ /\.c$/ && defined $stat &&
$stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
Expand Down Expand Up @@ -3291,12 +3313,6 @@ sub process {
WARN("EXPORTED_WORLD_WRITABLE",
"Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
}

# Check for memset with swapped arguments
if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) {
ERROR("MEMSET",
"memset size is 3rd argument, not the second.\n" . $herecurr);
}
}

# If we have no input at all, then there is nothing to report on
Expand Down

0 comments on commit 91f7006

Please sign in to comment.