Hi there! I recently noticed a couple of patches by Roel Kluin on lkml that looked interesting to me, and I tried to write a semantic patch to find such occurrences. One of the lkml patches:
can: wrong index used in inner loop http://groups.google.com/group/linux.kernel/browse_thread/thread/6d1e353cedcf5862 Here are nested 'for' loops using the same iterator, and the inner one will overwrite the outer one. In this case, the inner loop is within an 'if' clause. Simplified: for ( i = 0; ... ; ++i ) { ... if ( ... ) { ... for ( i = 0; ... ; ++i ) { ... } ... } } A very simple semantic patch I came up with to point to this pattern would look like: @@ expression a; @@ * for ( ... ; ... ; a ) { ... * a ... } However, this semantic patch fails when 'if' is replaced with 'switch', like here: nfsd: wrong index used in inner loop http://groups.google.com/group/linux.kernel/browse_thread/thread/0366edcfe5497481 Simplified: for ( i = 0; ... ; ++i ) { ... switch ( ... ) { ... case ...: ... for ( i = 0; ... ; ++i ) { ... } ... } } I'm afraid I'm stuck trying to find the expression within the 'switch'. Could you possibly give me a hint what I'm doing wrong? Best regards, Nicolas Kaiser _______________________________________________ Cocci mailing list [email protected] http://lists.diku.dk/mailman/listinfo/cocci (Web access from inside DIKUs LAN only)
