@@ -236,13 +236,13 @@ bson_aligned_alloc0(size_t alignment /* IN */, size_t num_bytes /* IN */)
236
236
*
237
237
* bson_array_alloc --
238
238
*
239
- * Allocates zero-filled, aligned memory for an array of objects,
240
- * checking for cases of n = 0 and integer overflow in type_size * len,
241
- * in which case NULL is returned.
239
+ * Allocates memory for an array of objects, checking for cases of
240
+ * n = 0 and integer overflow in type_size * len, in which case NULL
241
+ * is returned.
242
242
*
243
243
* Parameters:
244
244
* @type_size: The size of each object's type in bytes.
245
- * @len : The number of objects to allocate.
245
+ * @num_elems : The number of objects to allocate.
246
246
*
247
247
* Returns:
248
248
* A pointer if successful; otherwise abort() is called and this
@@ -255,13 +255,47 @@ bson_aligned_alloc0(size_t alignment /* IN */, size_t num_bytes /* IN */)
255
255
*/
256
256
257
257
void *
258
- bson_array_alloc (size_t type_size /* IN */ , size_t len /* IN */ )
258
+ bson_array_alloc (size_t type_size /* IN */ , size_t num_elems /* IN */ )
259
259
{
260
260
void * mem = NULL ;
261
- size_t num_bytes = type_size * len ;
261
+ size_t num_bytes = type_size * num_elems ;
262
262
263
- if (BSON_LIKELY (num_bytes ) && BSON_LIKELY (type_size == num_bytes / len )) {
264
- mem = bson_aligned_alloc0 (BSON_ALIGNOF (type_size ), num_bytes );
263
+ if (BSON_LIKELY (num_bytes ) && BSON_LIKELY (num_elems == num_bytes / type_size )) {
264
+ mem = bson_malloc (num_bytes );
265
+ }
266
+ return mem ;
267
+ }
268
+
269
+ /*
270
+ *--------------------------------------------------------------------------
271
+ *
272
+ * bson_array_alloc0 --
273
+ *
274
+ * Like bson_array_alloc() except the memory is zeroed after allocation
275
+ * for convenience.
276
+ *
277
+ * Parameters:
278
+ * @type_size: The size of each object's type in bytes.
279
+ * @num_elems: The number of objects to allocate.
280
+ *
281
+ * Returns:
282
+ * A pointer if successful; otherwise abort() is called and this
283
+ * function will never return.
284
+ *
285
+ * Side effects:
286
+ * None.
287
+ *
288
+ *--------------------------------------------------------------------------
289
+ */
290
+
291
+ void *
292
+ bson_array_alloc0 (size_t type_size /* IN */ , size_t num_elems /* IN */ )
293
+ {
294
+ void * mem = NULL ;
295
+ size_t num_bytes = type_size * num_elems ;
296
+
297
+ if (BSON_LIKELY (num_bytes ) && BSON_LIKELY (num_elems == num_bytes / type_size )) {
298
+ mem = bson_malloc0 (num_bytes );
265
299
}
266
300
return mem ;
267
301
}
0 commit comments