KernelNewbies:

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 see bli2 "^ for \(".

@V is translated to [[:alpha:]_]+[[:alnum:]_]*, which matches a local variable. @d matches any number and contains parentheses, that's why we have to use \3, as a back-reference to match the second @d.

This currently 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.

More advanced examples can be found here [wiki:roelkluin/gres_tests/loops gres_tests/loops]

KernelNewbies: roelkluin/gres_examples (last edited 2010-02-18 21:23:23 by d133062)