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

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

Revision 7 as of 2017-12-30 01:30:26
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 to match the second @d we use \3 as a back-reference. \{.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 gres_tests/loops.

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