aboutsummaryrefslogtreecommitdiff
path: root/lib/sset.h
diff options
context:
space:
mode:
authorAlex Wang <alexw@nicira.com>2013-07-22 09:19:56 -0700
committerBen Pfaff <blp@nicira.com>2013-07-22 11:20:43 -0700
commit55d2690646769467b6d26ad55516ff6eeb12869d (patch)
tree19b86a6ef64c96d9a1a98ff53863062b21c8d7e3 /lib/sset.h
parent21a0e105f175926d1d10d324565915ccb96fd28b (diff)
clang: Fix segfault in unit tests.
It seems that 'clang' compiler applies strict protection on pointer dereference. And it causes unexpected execution in macro functions like "HMAP_FOR_EACH()" and unit test failures. This commit fixes this issue and pass all unit tests. Co-authored-by: Ethan Jackson <ethan@nicira.com> Signed-off-by: Alex Wang <alexw@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/sset.h')
-rw-r--r--lib/sset.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/sset.h b/lib/sset.h
index 625cea98..1e864efc 100644
--- a/lib/sset.h
+++ b/lib/sset.h
@@ -70,12 +70,12 @@ struct sset_node *sset_at_position(const struct sset *,
/* Iteration macros. */
#define SSET_FOR_EACH(NAME, SSET) \
for ((NAME) = SSET_FIRST(SSET); \
- SSET_NODE_FROM_NAME(NAME) != NULL; \
+ NAME != NULL; \
(NAME) = SSET_NEXT(SSET, NAME))
#define SSET_FOR_EACH_SAFE(NAME, NEXT, SSET) \
for ((NAME) = SSET_FIRST(SSET); \
- (SSET_NODE_FROM_NAME(NAME) != NULL \
+ (NAME != NULL \
? (NEXT) = SSET_NEXT(SSET, NAME), true \
: false); \
(NAME) = (NEXT))
@@ -87,7 +87,9 @@ const char **sset_sort(const struct sset *);
#define SSET_NODE_FROM_HMAP_NODE(HMAP_NODE) \
CONTAINER_OF(HMAP_NODE, struct sset_node, hmap_node)
#define SSET_NAME_FROM_HMAP_NODE(HMAP_NODE) \
- (CONST_CAST(const char *, (SSET_NODE_FROM_HMAP_NODE(HMAP_NODE)->name)))
+ HMAP_NODE == NULL \
+ ? NULL \
+ : (CONST_CAST(const char *, (SSET_NODE_FROM_HMAP_NODE(HMAP_NODE)->name)))
#define SSET_NODE_FROM_NAME(NAME) CONTAINER_OF(NAME, struct sset_node, name)
#define SSET_FIRST(SSET) SSET_NAME_FROM_HMAP_NODE(hmap_first(&(SSET)->map))
#define SSET_NEXT(SSET, NAME) \