-
Notifications
You must be signed in to change notification settings - Fork 456
CDRIVER-6055 Audit array allocations #2098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Julia-Garland
merged 13 commits into
mongodb:master
from
Julia-Garland:audit-array-allocations.cdriver-6055
Sep 3, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
09ffe7e
Add bson_array_alloc function
Julia-Garland b06e491
Replace in situ multiplication with array_alloc function call
Julia-Garland cccae5d
Use correct alignof macro
Julia-Garland b4c8bb8
Split bson_alloc_array into two versions for bson_malloc0 calls; alig…
Julia-Garland 34fa159
Fix incorrect call
Julia-Garland de6fd91
Create docs page for bson_alloc_array(0)
Julia-Garland 1a955ac
Extend title underline
Julia-Garland fcd73e6
Fix function name in docs
Julia-Garland cbe412e
Add a BSON_ARRAY_ALLOC macro to handle casting from void*
Julia-Garland 27caede
Remove "at least sizeof(void*) bytes" from documentation
Julia-Garland 286c43a
kevinAlbs suggestions
Julia-Garland 03910db
Tweak mlib include
Julia-Garland 520ee4d
Initialize num_bytes
Julia-Garland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
:man_page: bson_array_alloc | ||
|
||
bson_array_alloc() | ||
================== | ||
|
||
Synopsis | ||
-------- | ||
|
||
.. code-block:: c | ||
|
||
#define BSON_ARRAY_ALLOC(Count, Type) \ | ||
(Type*) bson_array_alloc (Count, sizeof (Type)) | ||
|
||
void * | ||
bson_array_alloc (size_t num_elems, size_t elem_size); | ||
|
||
Parameters | ||
---------- | ||
|
||
* ``num_elems``: A size_t containing the number of objects to allocate. | ||
* ``elem_size``: A size_t containing the size of each object in bytes. | ||
|
||
Description | ||
----------- | ||
|
||
This is a portable ``malloc()`` wrapper to allocate an array of objects. | ||
|
||
If ``num_elems * elem_size`` cannot be represented in a size_t or there was a failure to allocate ``num_elems * elem_size`` bytes, the process will be aborted. | ||
|
||
.. warning:: | ||
|
||
This function will abort on failure to allocate memory. | ||
|
||
Returns | ||
------- | ||
|
||
A pointer to a memory region which *HAS NOT* been zeroed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
:man_page: bson_array_alloc0 | ||
|
||
bson_array_alloc0() | ||
=================== | ||
|
||
Synopsis | ||
-------- | ||
|
||
.. code-block:: c | ||
|
||
#define BSON_ARRAY_ALLOC0(Count, Type) \ | ||
(Type*) bson_array_alloc0 (Count, sizeof (Type)) | ||
|
||
void * | ||
bson_array_alloc0 (size_t num_elems, size_t elem_size); | ||
|
||
Parameters | ||
---------- | ||
|
||
* ``num_elems``: A size_t containing the number of objects to allocate. | ||
* ``elem_size``: A size_t containing the size of each object in bytes. | ||
|
||
Description | ||
----------- | ||
|
||
This is a portable ``calloc()`` wrapper to allocate an array of objects that also sets the memory to zero. | ||
|
||
If ``num_elems * elem_size`` cannot be represented in a size_t or there was a failure to allocate ``num_elems * elem_size`` bytes, the process will be aborted. | ||
|
||
.. warning:: | ||
|
||
This function will abort on failure to allocate memory. | ||
|
||
Returns | ||
------- | ||
|
||
A pointer to a memory region which *HAS* been zeroed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.