Open
Bug 564858
Opened 14 years ago
Updated 2 years ago
Warn when a macro is not properly parenthesized
Categories
(Developer Infrastructure :: Source Code Analysis, task, P4)
Developer Infrastructure
Source Code Analysis
Tracking
(Not tracked)
NEW
People
(Reporter: jrmuizel, Unassigned)
References
Details
At the time of filing cairo has the following macro:
#if defined (__GNUC__)
#define cairo_container_of(ptr, type, member) ({ \
const __typeof__ (((type *) 0)->member) *mptr__ = (ptr); \
(type *) ((char *) mptr__ - offsetof (type, member)); \
})
#else
#define cairo_container_of(ptr, type, member) \
(type *)((char *) (ptr) - (char *) &((type *)0)->member)
#endif
This macro non __GNUC__ version is missing a set of parenthesis which caused a compile error when used like 'cairo_container_of(p, struct a, foo)->pop' because '->' binds more tightly than casts.
It would be nice if we had a static analysis pass that checked whether all of the expression members in a macro remain as a unit in the expression tree. i.e. in the previous example, the '->' operator is inserted into the middle of the macro's expression tree (it has both parent and child expressions that are part of the same macro expansion).
Updated•14 years ago
|
Blocks: static_analyses
Updated•7 years ago
|
Product: Core → Firefox Build System
Updated•4 years ago
|
Priority: -- → P5
Updated•4 years ago
|
Type: defect → task
Reporter | ||
Comment 2•4 years ago
|
||
I ran into another version of this with the f()
macro here:
https://github.com/mozilla/gecko-dev/blob/5ee82cb26c8af72fbc634cc5995245a067515d38/gfx/qcms/chain.c#L75
Flags: needinfo?(jmuizelaar)
Updated•4 years ago
|
Priority: P5 → P4
Updated•2 years ago
|
Product: Firefox Build System → Developer Infrastructure
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•