Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1475906
| From | Julia Lawall <julia.lawall@lip6.fr> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: Possible code defects: macros and precedence |
| Date | 2016-09-04 12:20 +0200 |
| Message-ID | <sdCGS-5AL-17@gated-at.bofh.it> (permalink) |
| References | <sdo1b-nU-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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 arguments passed to the > macro are not correctly parenthesized by the macro? > > Something like: > > #define A 1 > #define B 2 > #define shift(val) (val << 1) > > where a use is: > > int c = shift(A | B) > > where the actual result is 5 but the expected result is 6? > > Can either tool suggest changing the macro to > > #define shift(val) ((val) << 1) Coccinelle could do this. It is possible to match macro parameters, and it is possible to match binary operators generically. I can look into it. julia
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Possible code defects: macros and precedence Joe Perches <joe@perches.com> - 2016-09-03 20:40 +0200
Re: Possible code defects: macros and precedence Dan Carpenter <dan.carpenter@oracle.com> - 2016-09-03 22:20 +0200
[PATCH] checkpatch: Add a --strict test for macro argument reuse and precedence Joe Perches <joe@perches.com> - 2016-09-04 00:30 +0200
Re: [PATCH] checkpatch: Add a --strict test for macro argument reuse and precedence Joe Perches <joe@perches.com> - 2016-09-04 16:50 +0200
Re: Possible code defects: macros and precedence Julia Lawall <julia.lawall@lip6.fr> - 2016-09-04 12:20 +0200
Re: Possible code defects: macros and precedence Joe Perches <joe@perches.com> - 2016-09-04 17:10 +0200
csiph-web