Require a pointer + macro arg protection

pull/2533/head
David Garcia Quintas 10 years ago
parent 9b768a5fe9
commit 699b0f999e
  1. 10
      include/grpc/support/useful.h
  2. 6
      test/core/support/useful_test.c

@ -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 */

@ -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;

Loading…
Cancel
Save