Skip to content

Commit 05bd56a

Browse files
author
Micah Scott
committed
bugfix for test_bson_reserve_buffer_errors
The earlier fix for a bug in allocating bson_t near the max size revealed a flawed test that was only succeeding because of the allocation bug. This fixes the test to identify both sides of the boundary: we fail to allocate a bson_t that's one byte too large, and on 64-bit platforms we allocate a max-sized bson_t.
1 parent 57a2a0d commit 05bd56a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/libbson/tests/test-bson.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,11 @@ test_bson_reserve_buffer_errors (void)
18861886
uint32_t len_le;
18871887

18881888
/* too big */
1889-
ASSERT (!bson_reserve_buffer (&bson, (uint32_t) (INT32_MAX - bson.len - 1)));
1889+
ASSERT (!bson_reserve_buffer (&bson, (uint32_t) (BSON_MAX_SIZE - bson.len + 1u)));
1890+
/* exactly the maximum size */
1891+
#if BSON_WORD_SIZE > 32
1892+
ASSERT (bson_reserve_buffer (&bson, (uint32_t) (BSON_MAX_SIZE - bson.len)));
1893+
#endif
18901894

18911895
/* make a static bson, it refuses bson_reserve_buffer since it's read-only */
18921896
bson_destroy (&bson);

0 commit comments

Comments
 (0)