summaryrefslogtreecommitdiffstats
path: root/cpukit/include/sys
diff options
context:
space:
mode:
authordab <dab@FreeBSD.org>2018-06-28 17:01:04 +0000
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-08-08 08:15:17 +0200
commitb37ef68873b5dbc2f284dd874b0ee99b11841c4d (patch)
treed882986ce68ac4449f16cd15c5701c983521fd9b /cpukit/include/sys
parentsys/sys: further adoption of SPDX licensing ID tags. (diff)
downloadrtems-b37ef68873b5dbc2f284dd874b0ee99b11841c4d.tar.bz2
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@scriptkiddie.org> 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
Diffstat (limited to 'cpukit/include/sys')
-rw-r--r--cpukit/include/sys/event.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/cpukit/include/sys/event.h b/cpukit/include/sys/event.h
index 92f4f57ce2..b3ba98dd5d 100644
--- a/cpukit/include/sys/event.h
+++ b/cpukit/include/sys/event.h
@@ -49,6 +49,25 @@
#define EVFILT_EMPTY (-13) /* empty send socket buf */
#define EVFILT_SYSCOUNT 13
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#define EV_SET(kevp_, a, b, c, d, e, f) do { \
+ *(kevp_) = (struct kevent){ \
+ .ident = (a), \
+ .filter = (b), \
+ .flags = (c), \
+ .fflags = (d), \
+ .data = (e), \
+ .udata = (f), \
+ .ext[0] = 0, \
+ .ext[1] = 0, \
+ .ext[2] = 0, \
+ .ext[3] = 0, \
+ }; \
+} while(0)
+#else /* Pre-C99 or not STDC (e.g., C++) */
+/* The definition of the local variable kevp could possibly conflict
+ * with a user-defined value passed in parameters a-f.
+ */
#define EV_SET(kevp_, a, b, c, d, e, f) do { \
struct kevent *kevp = (kevp_); \
(kevp)->ident = (a); \
@@ -62,6 +81,7 @@
(kevp)->ext[2] = 0; \
(kevp)->ext[3] = 0; \
} while(0)
+#endif
struct kevent {
__uintptr_t ident; /* identifier for this event */