KernelNewbies
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Kernel Hacking

  • Frontpage

  • Kernel Hacking

  • Kernel Documentation

  • Kernel Glossary

  • FAQ

  • Found a bug?

  • Kernel Changelog

  • Upstream Merge Guide

Projects

  • KernelJanitors

  • KernelMentors

  • KernelProjects

Community

  • Why a community?

  • Regional Kernelnewbies

  • Personal Pages

  • Upcoming Events

References

  • Mailing Lists

  • Related Sites

  • Programming Links

Wiki

  • Recent Changes

  • Site Editors

  • Side Bar

  • Tips for Editors

  • Hosted by WikiWall

Navigation

  • RecentChanges
  • FindPage
  • HelpContents
Revision 2 as of 2017-12-30 01:30:06
KernelNewbies:
  • roelkluin
  • gres_tests
  • loops

First store all occurrences of loops in a file. gg -A40 "(while|for)" -- '*.c' '*.h' > ../out/loop_A40

Error: the same index is used in a nested loop

gres --FiL="../out/loop_A40" \
"(while \(|for \([^;]*;) @...&@ [+-]* (@w) ([+-][+-] [<>]|[<>]=) ((@K|@d|@K \(...\))) @&...@ (;\(-..\))?\)
 @in_branches
 (while \(|for \([^;]*;) @...&@ [+-]* \6 ([+-][+-] [<>]|[<>]=) ((@K|@d|@K \(...\))) @&...@ (;\(-..\))?\)" | less

Error: the same index is used in the header of a nested for loop

gres --FiL="../out/loop_A40" \
"(while \(|for \([^;]*;) @...&@ [+-]* (@w) ([+-][+-] [<>]|[<>]=) ((@K|@d|@K \(...\))) @&...@ (;\(-..\))?\)
 @in_branches \n
 for \(\(-8.\)@Q2\6@Q1\(-8.\)\)" | less

The test after the loop is off by 1 (extended example of gres_examples):

gres --FiL="../out/loop_A40" \
"while \( @...&|@ (@V) (<|\!=) (@d|@w) @&|...@ \) (\{\{-..\} \n)? \5 ([+*|]=|= \5 \+)@n
if \( @...&|@ \5 (>|<=) \7 @&|...@ \)" \
"(for \([^;]*;|while \() @...&|@
         \+* (@V) (<|\!=|\+\+ <=) (@d|@w) @&|...@
         (; (\+\+ \6|\6 \+\+|\6 = \6 \+ 1|\6 = 1 \+ \6))? \)
    \{.8.\}
@n
if \( @...&|@ \6 (>|<=) \8 @&|...@ \)"

Similarly off by one after decrementing in a loop:

gres --FiL="../out/loop_A40" \
"while \( @...&|@ (@V) (>|\!=) (@d|@w) @&|...@ \) (\{\{-..\} \n)? \5 (-=|= \5 -)@n
if \( @...&|@ \5 (<|>=) \7 @&|...@ \)" \
"(for \([^;]*;|while \() @...&|@
         -* (@V) (>|\!=) (@d|@w) @&|...@
         (; (-- \6|\6 --|\6 = \6 - 1|\6 = 1 - \6))? \)
    \{.8.\}
@n
if \( @...&|@ \6 (<|>=) \8 @&|...@ \)"

Using a variable after the loop, can be out of bounds after max or before min.

gres --FiL="../out/loop_A40" \
"(while \(|for \([^;]*;) @...&@ [+-]* (@w) ([+-][+-] [<>]|[+-][+-] [\!]=|[<>]=)? ((@K|@d|@K \(...\)))? @&...@ (;\(-..\))?\)
   @branch@n
 (for \()? \6 .?=@n
 [^\n]*\[ \6 \]" \
"(while \(|for \([^;]*;) @...&@ [+-]* (@w) ([+-][+-] [<>]|[+-][+-] [\!]=|[<>]=)? ((@K|@d|@K \(...\)))? @&...@ (;\(-..\))?\)
   @branch@n
 [^\n]*\[ \6 \]" | less

break in loop, but the variable after loop, can be out of bounds after max or before min.

gres --FiL="../out/loop_A40" \
"if \(@...&@ [+-]* (@w) ([+-][+-] [<>]|[+-][+-] [\!]=|[<>]=)? ((@K|@d|@K \(...\)))? @&...@ (;\(-..\))?\)
  (break ;|\{-8.\}\n break; \})
 \{-8.\}\}@n
 (for \()? \5 .?=@n
[^\n]*\[ \5 \]" \
"if \(@...&@ [+-]* (@w) ([+-][+-] [<>]|[+-][+-] [\!]=|[<>]=)? ((@K|@d|@K \(...\)))? @&...@ (;\(-..\))?\)
  (break ;|\{-8.\}\n break; \})
 \{-8.\}\}@n
[^\n]*\[ \5 \]" | less
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01