Re: Possible code defects: macros and precedence

2016-09-20 Thread Julia Lawall
On Tue, 20 Sep 2016, Joe Perches wrote: > On Tue, 2016-09-20 at 15:14 +0200, Julia Lawall wrote: > > The semantic patch below finds a binary operator in a macro and a binary > > operator in the use of the macro, and checks if the priority of the > > operator in the macro is higher (lower number)

Re: Possible code defects: macros and precedence

2016-09-20 Thread Joe Perches
On Tue, 2016-09-20 at 15:14 +0200, Julia Lawall wrote: > The semantic patch below finds a binary operator in a macro and a binary > operator in the use of the macro, and checks if the priority of the > operator in the macro is higher (lower number) than the priority of the > operator in the use.  I

Re: Possible code defects: macros and precedence

2016-09-20 Thread Joe Perches
On Tue, 2016-09-20 at 10:07 -0700, Joe Perches wrote: > On Tue, 2016-09-20 at 15:14 +0200, Julia Lawall wrote: > > The semantic patch below finds a binary operator in a macro and a binary > > operator in the use of the macro, and checks if the priority of the > > operator in the macro is higher (lo

Re: Possible code defects: macros and precedence

2016-09-20 Thread Joe Perches
On Tue, 2016-09-20 at 15:14 +0200, Julia Lawall wrote: > The semantic patch below finds a binary operator in a macro and a binary > operator in the use of the macro, and checks if the priority of the > operator in the macro is higher (lower number) than the priority of the > operator in the use.  I

Re: Possible code defects: macros and precedence

2016-09-20 Thread Julia Lawall
The semantic patch below finds a binary operator in a macro and a binary operator in the use of the macro, and checks if the priority of the operator in the macro is higher (lower number) than the priority of the operator in the use. If this is the case, it adds parentheses in the use, which is no

Re: Possible code defects: macros and precedence

2016-09-18 Thread Joe Perches
On Sun, 2016-09-18 at 07:09 +0200, Julia Lawall wrote: > On Sat, 17 Sep 2016, Joe Perches wrote: > > I also submitted a similar checkpatch addition that looks > > for non-comma operators used macro arguments in function > > definitions. > > > > The checkpatch test has the same weakness as the cocci

Re: Possible code defects: macros and precedence

2016-09-18 Thread Joe Perches
On Sun, 2016-09-18 at 06:57 +0200, Julia Lawall wrote: > You did say that checkpatch was giving a lot of noise.  In the end, is it > actually just that there are a lot of changes to make Actually, the first attempt used just the checkpatch $Operators pattern match which also matches a comma so the

Re: Possible code defects: macros and precedence

2016-09-17 Thread Julia Lawall
On Sat, 17 Sep 2016, Joe Perches wrote: > On Sat, 2016-09-17 at 22:24 +0200, Julia Lawall wrote: > > diff -u -p a/lib/sha1.c b/lib/sha1.c > [] > > @@ -49,18 +49,18 @@ > >   * the input data, the next mix it from the 512-bit array. > >   */ > >  #define SHA_SRC(t) get_unaligned_be32((__u32 *)data

Re: Possible code defects: macros and precedence

2016-09-17 Thread Julia Lawall
On Sat, 17 Sep 2016, Joe Perches wrote: > On Sat, 2016-09-17 at 22:24 +0200, Julia Lawall wrote: > > (A 2.2MB message that (perhaps thankfully) didn't get through to lkml) > > > Below is the Coccinelle output for the case where the definition of the > > macro is a single expression.  There is al

Re: Possible code defects: macros and precedence

2016-09-17 Thread Joe Perches
On Sat, 2016-09-17 at 22:24 +0200, Julia Lawall wrote: (A 2.2MB message that (perhaps thankfully) didn't get through to lkml) > Below is the Coccinelle output for the case where the definition of the > macro is a single expression.  There is also the case where it is a > sequence of statements, b

Re: Possible code defects: macros and precedence

2016-09-17 Thread Joe Perches
On Sat, 2016-09-17 at 22:24 +0200, Julia Lawall wrote: > diff -u -p a/lib/sha1.c b/lib/sha1.c [] > @@ -49,18 +49,18 @@ >   * the input data, the next mix it from the 512-bit array. >   */ >  #define SHA_SRC(t) get_unaligned_be32((__u32 *)data + t) > -#define SHA_MIX(t) rol32(W(t+13) ^ W(t+8) ^ W(t+

Re: Possible code defects: macros and precedence

2016-09-04 Thread Joe Perches
On Sun, 2016-09-04 at 18:10 +0800, Julia Lawall wrote: > On Sat, 3 Sep 2016, Joe Perches wrote: > > There are many nominally incorrect macro definitions > > in linux-kernel source where parentheses are not used > > for various macros arguments with calculations. > > > > Does coccinelle or smatch ha

Re: Possible code defects: macros and precedence

2016-09-04 Thread Julia Lawall
On Sat, 3 Sep 2016, Joe Perches wrote: > There are many nominally incorrect macro definitions > in linux-kernel source where parentheses are not used > for various macros arguments with calculations. > > Does coccinelle or smatch have the ability to detect > potential macro misuse where argument

Re: Possible code defects: macros and precedence

2016-09-03 Thread Dan Carpenter
No. I can't think of a way to write a script for that in smatch. It works on the pre-processed code. There is a hack around to tell if code is inside a macro or not, but you can't tell if code is a macro parameter. regards, dan carpenter

Possible code defects: macros and precedence

2016-09-03 Thread Joe Perches
There are many nominally incorrect macro definitions in linux-kernel source where parentheses are not used for various macros arguments with calculations. Does coccinelle or smatch have the ability to detect potential macro misuse where arguments passed to the macro are not correctly parenthesized