History

checkpatch: check for common memset parameter issues against statments

Move the memset checks over to work against the statement. Also add checks for 0 and 1 used as lengths. Generally these indicate badly ordered parameters.

Andy Whitcroft committed 14 years ago

Commit 554e1651 parent f74bd191 file · +22 −6Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+22−6
@@ -3120,6 +3120,28 @@ sub process { · 3119 unmodified lines
3120 "Avoid line continuations in quoted strings\n" . $herecurr);3120 "Avoid line continuations in quoted strings\n" . $herecurr);
3121 }3121 }
3122 3122
3123# Check for misused memsets
3124 if (defined $stat && $stat =~ /\bmemset\s*\((.*)\)/s) {
3125 my $args = $1;
3126
3127 # Flatten any parentheses and braces
3128 while ($args =~ s/\([^\(\)]*\)/10/s ||
3129 $args =~ s/\{[^\{\}]*\}/10/s ||
3130 $args =~ s/\[[^\[\]]*\]/10/s)
3131 {
3132 }
3133 # Extract the simplified arguments.
3134 my ($ms_addr, $ms_val, $ms_size) =
3135 split(/\s*,\s*/, $args);
3136 if ($ms_size =~ /^(0x|)0$/i) {
3137 ERROR("MEMSET",
3138 "memset size is 3rd argument, not the second.\n" . $herecurr);
3139 } elsif ($ms_size =~ /^(0x|)1$/i) {
3140 WARN("MEMSET",
3141 "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . $herecurr);
3142 }
3143 }
3144
3123# check for new externs in .c files.3145# check for new externs in .c files.
3124 if ($realfile =~ /\.c$/ && defined $stat &&3146 if ($realfile =~ /\.c$/ && defined $stat &&
3125 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)3147 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
@@ -3291,12 +3313,6 @@ sub process { · 165 unmodified lines
3291 WARN("EXPORTED_WORLD_WRITABLE",3313 WARN("EXPORTED_WORLD_WRITABLE",
3292 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);3314 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
3293 }3315 }
3294
3295 # Check for memset with swapped arguments
3296 if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) {
3297 ERROR("MEMSET",
3298 "memset size is 3rd argument, not the second.\n" . $herecurr);
3299 }
3300 }3316 }
3301 3317
3302 # If we have no input at all, then there is nothing to report on3318 # If we have no input at all, then there is nothing to report on