diff options
author | David Garcia Quintas <dgq@google.com> | 2015-07-15 17:12:35 -0700 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2015-07-15 17:12:35 -0700 |
commit | ed7e8550f5e88a31222514123058a6a1dd8f955a (patch) | |
tree | 42b8e321f92c457f0b3a4c5ec8bfd056e13574e6 | |
parent | 305e3bd6359f646746a0046f8fc44c82270c16ef (diff) |
Require a pointer + macro arg protection
-rw-r--r-- | include/grpc/support/useful.h | 10 | ||||
-rw-r--r-- | test/core/support/useful_test.c | 6 |
2 files changed, 8 insertions, 8 deletions
diff --git a/include/grpc/support/useful.h b/include/grpc/support/useful.h index 6eb212a311..d3d8ad6437 100644 --- a/include/grpc/support/useful.h +++ b/include/grpc/support/useful.h @@ -52,13 +52,13 @@ b = x; \ } while (0) -/** Set the \a n-th bit of \a i */ -#define GPR_BITSET(i, n) (i |= (1u << n)) +/** Set the \a n-th bit of \a i (a mutable pointer). */ +#define GPR_BITSET(i, n) ((*(i)) |= (1u << n)) -/** Clear the \a n-th bit of \a i */ -#define GPR_BITCLEAR(i, n) (i &= ~(1u << n)) +/** Clear the \a n-th bit of \a i (a mutable pointer). */ +#define GPR_BITCLEAR(i, n) ((*(i)) &= ~(1u << n)) /** Get the \a n-th bit of \a i */ -#define GPR_BITGET(i, n) ((i & (1u << n)) != 0) +#define GPR_BITGET(i, n) (((i) & (1u << n)) != 0) #endif /* GRPC_SUPPORT_USEFUL_H */ diff --git a/test/core/support/useful_test.c b/test/core/support/useful_test.c index 0804a81b7c..5827f0a627 100644 --- a/test/core/support/useful_test.c +++ b/test/core/support/useful_test.c @@ -56,10 +56,10 @@ int main(int argc, char **argv) { GPR_ASSERT(GPR_ARRAY_SIZE(four) == 4); GPR_ASSERT(GPR_ARRAY_SIZE(five) == 5); - GPR_ASSERT(GPR_BITSET(bitset, 3) == 8); + GPR_ASSERT(GPR_BITSET(&bitset, 3) == 8); GPR_ASSERT(GPR_BITGET(bitset, 3) == 1); - GPR_ASSERT(GPR_BITSET(bitset, 1) == 10); - GPR_ASSERT(GPR_BITCLEAR(bitset, 3) == 2); + GPR_ASSERT(GPR_BITSET(&bitset, 1) == 10); + GPR_ASSERT(GPR_BITCLEAR(&bitset, 3) == 2); GPR_ASSERT(GPR_BITGET(bitset, 3) == 0); return 0; |