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 5 as of 2010-02-18 21:29:28
KernelNewbies:
  • roelkluin
  • gres_examples

To search for an erroneous pattern like this:

for (i = 0; i < n; i++) {}
...
if (i > n) ...

This is wrong because at the end of the loop i equals n and cannot be greater than n. To match this:

gres -A40 "^ for \(" \
"for \( (@V) = @d ; \1 < @d ; \1 \+\+ \)
    \{.8.\}
@n
if \( \1 > \3 \)" | less

The first string is used to get the git grep query. To see what is queried for execute

bli2 "^ for \("

It will print the extended regexp used in the query.

@V is translated to [[:alpha:]_]+[[:alnum:]_]*, which matches a local variable. @d matches any number in several formats, therefore it contains parentheses, that's why we use \3, as a back-reference to match the second @d. \{.8.\} matches anything between curly brackets, up to 8 nested curly brackets.

This results after about 10 seconds in a match:

---[ vi drivers/mmc/host/s3cmci.c +1209 ]---
        /* Set clock */
        for (mci_psc = 0; mci_psc < 255; mci_psc++) {
                ...
        }

        if (mci_psc > 255)
                mci_psc = 255;
        ...

Quite harmless so I left it.

I left this simple for explanatory reasons. A more advanced query to catch these errors, and others, can be found here [wiki:roelkluin/gres_tests/loops gres_tests/loops].

  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01