21
21
#include <bson/bson-json-private.h>
22
22
#include <common-string-private.h>
23
23
#include <common-json-private.h>
24
- #include <common-macros-private.h>
25
24
#include <bson/bson-iso8601-private.h>
26
25
27
26
#include <string.h>
@@ -61,31 +60,6 @@ typedef struct {
61
60
*/
62
61
static const uint8_t gZero ;
63
62
64
- /*
65
- *--------------------------------------------------------------------------
66
- *
67
- * _bson_next_power_of_two_for_alloc --
68
- *
69
- * Given a potential allocation length no greater than BSON_MAX_SIZE,
70
- * round it up to the next power of two without exceeding BSON_MAX_SIZE.
71
- *
72
- * Returns:
73
- * A value >= the input size and <= BSON_MAX_SIZE.
74
- *
75
- * Side effects:
76
- * None.
77
- *
78
- *--------------------------------------------------------------------------
79
- */
80
-
81
- static BSON_INLINE size_t
82
- _bson_next_power_of_two_for_alloc (size_t size )
83
- {
84
- MONGOC_DEBUG_ASSERT (size <= BSON_MAX_SIZE );
85
- size_t power_of_two = bson_next_power_of_two (size );
86
- return BSON_MIN (power_of_two , BSON_MAX_SIZE );
87
- }
88
-
89
63
/*
90
64
*--------------------------------------------------------------------------
91
65
*
@@ -116,7 +90,7 @@ _bson_impl_inline_grow (bson_impl_inline_t *impl, /* IN */
116
90
return true;
117
91
}
118
92
119
- req = _bson_next_power_of_two_for_alloc (impl -> len + size );
93
+ req = bson_next_power_of_two (impl -> len + size );
120
94
121
95
if (req <= BSON_MAX_SIZE ) {
122
96
data = bson_malloc (req );
@@ -176,7 +150,7 @@ _bson_impl_alloc_grow (bson_impl_alloc_t *impl, /* IN */
176
150
return true;
177
151
}
178
152
179
- req = _bson_next_power_of_two_for_alloc (req );
153
+ req = bson_next_power_of_two (req );
180
154
181
155
if ((req <= BSON_MAX_SIZE ) && impl -> realloc ) {
182
156
* impl -> buf = impl -> realloc (* impl -> buf , req , impl -> realloc_func_ctx );
@@ -194,8 +168,7 @@ _bson_impl_alloc_grow (bson_impl_alloc_t *impl, /* IN */
194
168
* _bson_grow --
195
169
*
196
170
* Grows the bson_t structure to be large enough to contain @size
197
- * bytes in addition to its current content. The caller is responsible
198
- * for ensuring the new summed size is <= BSON_MAX_SIZE.
171
+ * bytes.
199
172
*
200
173
* Returns:
201
174
* true if successful, false if the size would overflow.
@@ -210,9 +183,6 @@ static bool
210
183
_bson_grow (bson_t * bson , /* IN */
211
184
uint32_t size ) /* IN */
212
185
{
213
- // Already checked by caller in all build types
214
- MONGOC_DEBUG_ASSERT ((size_t ) bson -> len <= BSON_MAX_SIZE && (size_t ) size <= BSON_MAX_SIZE - (size_t ) bson -> len );
215
-
216
186
if ((bson -> flags & BSON_FLAG_INLINE )) {
217
187
return _bson_impl_inline_grow ((bson_impl_inline_t * ) bson , size );
218
188
}
@@ -2127,7 +2097,7 @@ bson_copy_to (const bson_t *src, bson_t *dst)
2127
2097
}
2128
2098
2129
2099
data = _bson_data (src );
2130
- len = _bson_next_power_of_two_for_alloc ((size_t ) src -> len );
2100
+ len = bson_next_power_of_two ((size_t ) src -> len );
2131
2101
2132
2102
adst = (bson_impl_alloc_t * ) dst ;
2133
2103
adst -> flags = BSON_FLAG_STATIC ;
@@ -2249,10 +2219,6 @@ bson_reserve_buffer (bson_t *bson, uint32_t size)
2249
2219
return NULL ;
2250
2220
}
2251
2221
2252
- MONGOC_DEBUG_ASSERT ((size_t ) bson -> len <= BSON_MAX_SIZE );
2253
- if ((size_t ) size > BSON_MAX_SIZE - (size_t ) bson -> len ) {
2254
- return NULL ;
2255
- }
2256
2222
if (!_bson_grow (bson , size )) {
2257
2223
return NULL ;
2258
2224
}
0 commit comments