mirror of
https://github.com/FRRouting/frr.git
synced 2025-04-30 13:37:17 +02:00
lib: add copy function for bitfield_t
Add a function to copy a bitfield_t structure. Add a ‘void *’ to ‘word_t *’ converstion in bf_init() to avoid the following error: > ./lib/bitfield.h: In function ‘bf_copy’: > ./lib/bitfield.h:75:12: error: request for implicit conversion from ‘void *’ to ‘word_t *’ {aka ‘unsigned int *’} not permitted in C++ [-Werror=c++-compat] > (v).data = XCALLOC(MTYPE_BITFIELD, ((v).m * sizeof(word_t))); \ > ^ > ./lib/bitfield.h:278:2: note: in expansion of macro ‘bf_init’ > bf_init(dst, WORD_SIZE * (src.m - 1)); > ^~~~~~~ Signed-off-by: Hiroki Shirokura <hiroki.shirokura@linecorp.com> Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
This commit is contained in:
parent
8300f2f56c
commit
c86a325285
|
@ -72,7 +72,8 @@ DECLARE_MTYPE(BITFIELD);
|
||||||
do { \
|
do { \
|
||||||
(v).n = 0; \
|
(v).n = 0; \
|
||||||
(v).m = ((N) / WORD_SIZE + 1); \
|
(v).m = ((N) / WORD_SIZE + 1); \
|
||||||
(v).data = XCALLOC(MTYPE_BITFIELD, ((v).m * sizeof(word_t))); \
|
(v).data = (word_t *)XCALLOC(MTYPE_BITFIELD, \
|
||||||
|
((v).m * sizeof(word_t))); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -268,6 +269,19 @@ static inline unsigned int bf_find_next_set_bit(bitfield_t v,
|
||||||
(v).data = NULL; \
|
(v).data = NULL; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
static inline bitfield_t bf_copy(bitfield_t src)
|
||||||
|
{
|
||||||
|
bitfield_t dst;
|
||||||
|
|
||||||
|
assert(bf_is_inited(src));
|
||||||
|
bf_init(dst, WORD_SIZE * (src.m - 1));
|
||||||
|
for (size_t i = 0; i < src.m; i++)
|
||||||
|
dst.data[i] = src.data[i];
|
||||||
|
dst.n = src.n;
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue