Changeset b37ef68 in rtems for cpukit/include/sys/event.h


Ignore:
Timestamp:
Jun 28, 2018, 5:01:04 PM (11 months ago)
Author:
dab <dab@…>
Branches:
master
Children:
1d00acb1
Parents:
bf026dd4
git-author:
dab <dab@…> (06/28/18 17:01:04)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/08/18 06:15:17)
Message:

Remove potential identifier conflict in the EV_SET macro.

PR43905 pointed out a problem with the EV_SET macro if the passed
struct kevent pointer were specified with an expression with side
effects (e.g., "kevp++"). This was fixed in rS110241, but by using a
local block that defined an internal variable (named "kevp") to get
the pointer value once. This worked, but could cause issues if an
existing variable named "kevp" is in scope. To avoid that issue,
jilles@ pointed out that "C99 compound literals and designated
initializers allow doing this cleanly using a macro". This change
incorporates that suggestion, essentially verbatim from jilles@
comment on PR43905, except retaining the old definition for pre-C99 or
non-STDC (e.g., C++) compilers.

PR: 43905
Submitted by: Jilles Tjoelker (jilles@)
Reported by: Lamont Granquist <lamont@…>
Reviewed by: jmg (no comments), jilles
MFC after: 1 week
Sponsored by: Dell EMC
Differential Revision: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=43905

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/sys/event.h

    rbf026dd4 rb37ef68  
    5050#define EVFILT_SYSCOUNT         13
    5151
     52#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
     53#define EV_SET(kevp_, a, b, c, d, e, f) do {    \
     54    *(kevp_) = (struct kevent){                 \
     55        .ident = (a),                           \
     56        .filter = (b),                          \
     57        .flags = (c),                           \
     58        .fflags = (d),                          \
     59        .data = (e),                            \
     60        .udata = (f),                           \
     61        .ext[0] = 0,                            \
     62        .ext[1] = 0,                            \
     63        .ext[2] = 0,                            \
     64        .ext[3] = 0,                            \
     65    };                                          \
     66} while(0)
     67#else /* Pre-C99 or not STDC (e.g., C++) */
     68/* The definition of the local variable kevp could possibly conflict
     69 * with a user-defined value passed in parameters a-f.
     70 */
    5271#define EV_SET(kevp_, a, b, c, d, e, f) do {    \
    5372        struct kevent *kevp = (kevp_);          \
     
    6382        (kevp)->ext[3] = 0;                     \
    6483} while(0)
     84#endif
    6585
    6686struct kevent {
Note: See TracChangeset for help on using the changeset viewer.