Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F158892550
D6848.id17824.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D6848.id17824.diff
View Options
Index: include/bitstring.h
===================================================================
--- include/bitstring.h
+++ include/bitstring.h
@@ -31,6 +31,7 @@
#include <stdlib.h>
#include <strings.h>
+#include <sys/param.h>
#include <sys/bitstring.h>
#endif /* _BITSTRING_H_ */
Index: sys/sys/bitstring.h
===================================================================
--- sys/sys/bitstring.h
+++ sys/sys/bitstring.h
@@ -65,6 +65,7 @@
#ifdef _KERNEL
#include <sys/libkern.h>
#include <sys/malloc.h>
+#include <sys/param.h>
#endif
#include <sys/types.h>
@@ -104,9 +105,8 @@
}
/*----------------------------- Public Interface -----------------------------*/
-/* Number of bytes consumed by a bit string of nbits bits */
-#define bitstr_size(_nbits) \
- (((_nbits) + _BITSTR_BITS - 1) / 8)
+/* Number of bytes allocated for a bit string of nbits bits */
+#define bitstr_size(_nbits) (roundup2(_nbits, _BITSTR_BITS) / 8)
/* Allocate a bit string initialized with no bits set. */
#ifdef _KERNEL
@@ -123,7 +123,7 @@
}
#endif
-/* Allocate a bit string on the stack with no bits set. */
+/* Allocate a bit string on the stack */
#define bit_decl(name, nbits) \
((name)[bitstr_size(nbits) / sizeof(bitstr_t)])
Index: tests/sys/sys/bitstring_test.c
===================================================================
--- tests/sys/sys/bitstring_test.c
+++ tests/sys/sys/bitstring_test.c
@@ -102,6 +102,17 @@
bit_nclear(test_struct.bitstr, 0, 8);
}
+ATF_TC_WITHOUT_HEAD(bitstr_size);
+ATF_TC_BODY(bitstr_size, tc)
+{
+ size_t sob = sizeof(bitstr_t);
+
+ ATF_CHECK_EQ(0, bitstr_size(0));
+ ATF_CHECK_EQ(sob, bitstr_size(1));
+ ATF_CHECK_EQ(sob, bitstr_size(sob * 8));
+ ATF_CHECK_EQ(2 * sob, bitstr_size(sob * 8 + 1));
+}
+
BITSTRING_TC_DEFINE(bit_set)
/* bitstr_t *bitstr, int nbits, const char *memloc */
{
@@ -407,6 +418,7 @@
{
ATF_TP_ADD_TC(tp, bitstr_in_struct);
+ ATF_TP_ADD_TC(tp, bitstr_size);
BITSTRING_TC_ADD(tp, bit_set);
BITSTRING_TC_ADD(tp, bit_clear);
BITSTRING_TC_ADD(tp, bit_ffs);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jun 8, 10:01 AM (2 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33809858
Default Alt Text
D6848.id17824.diff (1 KB)
Attached To
Mode
D6848: Fix bitstring allocation on 32-bit platforms
Attached
Detach File
Event Timeline
Log In to Comment