From: Ben Pfaff Date: Tue, 9 Feb 2016 00:52:44 +0000 (-0800) Subject: sset: Make sset iteration check the type of the nodes it's iterating. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=05e43c5ddca89236e6a674b3a6e5e8b6f98591e4 sset: Make sset iteration check the type of the nodes it's iterating. Without this additional check, SSET_FOR_EACH is happy to iterate over any type that has a struct hmap member named 'map'. We have a number of these: hmapx, shash, simap, and smap, in addition to sset. I guess another approach would be give each of these a unique member name, but the short name 'map' is nice too. Signed-off-by: Ben Pfaff Acked-by: Russell Bryant --- diff --git a/lib/sset.h b/lib/sset.h index 25d9c1cbe..7d1d49628 100644 --- a/lib/sset.h +++ b/lib/sset.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2013, 2015 Nicira, Inc. + * Copyright (c) 2011, 2012, 2013, 2015, 2016 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,10 +95,13 @@ const char **sset_sort(const struct sset *); ? 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_FIRST(SSET) \ + (BUILD_ASSERT_TYPE(SSET, struct sset *), \ + SSET_NAME_FROM_HMAP_NODE(hmap_first(&(SSET)->map))) #define SSET_NEXT(SSET, NAME) \ - SSET_NAME_FROM_HMAP_NODE( \ - hmap_next(&(SSET)->map, &SSET_NODE_FROM_NAME(NAME)->hmap_node)) + (BUILD_ASSERT_TYPE(SSET, struct sset *), \ + SSET_NAME_FROM_HMAP_NODE( \ + hmap_next(&(SSET)->map, &SSET_NODE_FROM_NAME(NAME)->hmap_node))) #ifdef __cplusplus }