+# 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);
+ }
+ }
+