Opened 11 years ago

Closed 11 years ago

#530 closed enhancement (fixed)

Type check link argument of list_get_instance macro

Reported by: Jiri Svoboda Owned by:
Priority: minor Milestone: 0.6.0
Component: helenos/unspecified Version: mainline
Keywords: Cc:
Blocker for: Depends on:
See also:


It bit me several times that list_get_instance() measures the offset of the link argument, but does not access it. The problem is that you can (mistakenly pass) any other field of the same structure and your code will compile (but crash).

Typical example is when you have a collection_t containing a list of foo_t where foo_t has the fields:

  • collection_t coll;
  • link_t lcoll;

it's all too easy to write list_get_instance(link, foo_t, coll) instead of list_get_instance(link, foo_t, lcoll).

I suggest we could improve the macro to check the type of the third argument in some way. Possible ways include:

  • access .prev or .next from the link and drop the result
  • pass address of link to a dummy type-checking function (e.g. a static inline function if you want to make sure it gets optimized away)

Change History (1)

comment:1 by Jiri Svoboda, 11 years ago

Milestone: 0.5.1
Resolution: fixed
Status: newclosed

Fixed in: mainline,1924

Note: See TracTickets for help on using tickets.