• Immutable Page
  • Info
  • Attachments

roelkluin

Roel Kluin

Email: [[roel.kluin@gmail.com)]]

I wrote a few tools to do a multiline (git) grep, see cvars howto. To use these tools you first source cvars and then do the searches in your git directory.

Search for conditions that execute the same code in the if and else branches

gres -A40 "^ if \(" \
"if \(.8.\)
        (@branch)
else \9" | less

Search for switch cases that execute the same code.

gres -A40 "^ case@S[^:]*: $" \
"case@S[^:\n]*: \n
(([^\n]*[^:{[:space:]] \n|\{.8.\}){2,})
(case@S[^:\n]*: ([^\n]*[^:{[:space:]] \n|\{.8.\})*)*
case@S[^:\n]*:
\1
(case|default)@S[^:\n]*:" | less

Some functions' return codes should be audited, the scripts below searches for code sections where this lacks.

Z="request_region kmalloc vmalloc kzalloc scsi_register create_proc_entry"
for z in $Z; do
echo "---[ $z ]---"
gres -B1 -A20 "^((.* (@w) =)? (\( @V \** \) )*)? $z \(" \
"@Q2(\**@w) = (\**@w = )*(\( @V \** \) )* $z \(...\) ;.*
(return|[&|(]) (\1 [=\!]= NULL|\!? \1|NULL [=\!]= \1) [&|)?;]" \
"@Q2(\**@w = )+(\( @V \** \) )* $z \(...\) ;"
done | less

Z="request_irq register_netdev misc_register create_proc_profile kernel_thread do_fork"
for z in $Z; do
echo "---[ $z ]---"
gres -B1 -A20 "^((.* (@w) =)? (\( @V \** \) )*)? $z \(" \
"@Q2(\**@w) = (\**@w = )*(\( @V \** \) )* $z \(...\) ;.*
(return|[&|(]) (\1 (<|[\!>=]=) 0|\!? \1|0 (>|[\!<=]=) \1) [)&|?;]" \
"@Q2(\**@w = )+(\( @V \** \) )* $z \(...\) ;"
done | less
Tell others about this page:

last edited 2010-01-20 01:31:31 by roelkluin