All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] cocci: char* indexing style for linux
@ 2014-08-16 20:06 Joe Perches
  2014-08-16 20:59 ` Joe Perches
  0 siblings, 1 reply; 23+ messages in thread
From: Joe Perches @ 2014-08-16 20:06 UTC (permalink / raw)
  To: cocci

Hi.

I tried this:

$ spatch --version
spatch version 1.0.0-rc21 without Python support and with PCRE support

$ cat char_index.cocci
@@
unsigned char * foo;
expression e;
@@

-	*(foo + e)
+	foo[e]

@@
char * foo;
expression e;
@@

-	*(foo + e)
+	foo[e]

$

with

$ spatch --recursive-includes -sp-file char_index.cocci drivers/net/ethernet/intel/e1000/e1000_ethtool.c

and got (after a very long time)

diff = 
--- drivers/net/ethernet/intel/e1000/e1000_ethtool.c
+++ /tmp/cocci-output-31725-95778b-e1000_ethtool.c
@@ -1395,9 +1395,9 @@ static int e1000_check_lbtest_frame(stru
 				    unsigned int frame_size)
 {
 	frame_size &= ~1;
-	if (*(skb->data + 3) == 0xFF) {
-		if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
-		   (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
+	if (skb->data[3] == 0xFF) {
+		if ((skb->data + frame_size / 2[10] == 0xBE) &&
+		   (skb->data + frame_size / 2[12] == 0xAF)) {
 			return 0;
 		}
 	}
Note: processing took   51.2s: drivers/net/ethernet/intel/e1000/e1000_ethtool.c
$

(originally I used spatch version 1.0.0-rc14,
 it took > 300 seconds, so that's improvement)

The suggested conversion to "sk->data + frame_size / 2[10]"
is not correct.

Can I make the char * foo test match the shortest
match or the statement s match the longest match
somehow?

I tried it with --disable-multi-pass and got the same
suggestion.

Is there another magic incantation?

cheers, Joe

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2014-08-18 11:55 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-16 20:06 [Cocci] cocci: char* indexing style for linux Joe Perches
2014-08-16 20:59 ` Joe Perches
2014-08-17 10:11   ` Julia Lawall
2014-08-17 13:01     ` Joe Perches
2014-08-17 16:09       ` SF Markus Elfring
2014-08-17 16:22         ` Joe Perches
2014-08-17 17:39           ` [Cocci] Conversion of some pointer arithmetic to array indexing style SF Markus Elfring
2014-08-17 17:48             ` Julia Lawall
2014-08-17 17:42           ` [Cocci] cocci: char* indexing style for linux Julia Lawall
2014-08-18  8:37             ` Lars-Peter Clausen
2014-08-18  9:40               ` Julia Lawall
2014-08-18 11:31                 ` SF Markus Elfring
2014-08-18 11:55                   ` Julia Lawall
2014-08-18  9:49               ` Julia Lawall
2014-08-18  9:57                 ` Lars-Peter Clausen
2014-08-18 10:33                   ` Julia Lawall
2014-08-18 10:55                     ` [Cocci] Clarification for array indexing style SF Markus Elfring
2014-08-18 10:59                       ` Julia Lawall
2014-08-18 10:34                 ` [Cocci] cocci: char* indexing style for linux Lars-Peter Clausen
2014-08-18  2:56       ` Julia Lawall
2014-08-18  8:08         ` [Cocci] Conversion of some pointer arithmetic to array indexing style SF Markus Elfring
2014-08-18  9:39           ` Julia Lawall
2014-08-18 10:35             ` SF Markus Elfring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.