mongo-c-driver
mongo-c-driver copied to clipboard
CDRIVER-5733 fix behavior of `bson_string_truncate`
Fixes behavior of bson_string_truncate
with large lengths. Verified with this patch build. See CDRIVER-5733 for details.
Also adds tests for behavior of bson_string_truncate
. In the process of this fix, other unexpected behavior was observed: bson_string_truncate
documents the truncated length "must be smaller or equal to the current length of the string.". However, bson_string_truncate
does not reject greater lengths.
bson_string_t *str = bson_string_new ("a");
bson_string_truncate (str, 2u); // Is not rejected.
ASSERT_CMPUINT32 (str->len, ==, 2u);
ASSERT_CMPUINT32 (str->alloc, ==, 4u);
bson_string_free (str, true);
This behavior is preserved (and now tested) for backwards compatibility. I expect there may be a possible use-case for calling bson_string_truncate
with larger lengths to reserve space.