Skip to content

Commit 54693de

Browse files
authored
CXX-3098 Throw from to_json when bson_init_static returns false (#1204)
1 parent 65e2759 commit 54693de

File tree

1 file changed

+6
-2
lines changed
  • src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx

1 file changed

+6
-2
lines changed

src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/json.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ void bson_free_deleter(std::uint8_t* ptr) {
3838

3939
std::string to_json_helper(document::view view, decltype(bson_as_json) converter) {
4040
bson_t bson;
41-
bson_init_static(&bson, view.data(), view.length());
41+
42+
if (!bson_init_static(&bson, view.data(), view.length())) {
43+
throw exception(error_code::k_failed_converting_bson_to_json);
44+
}
4245

4346
size_t size;
4447
auto result = converter(&bson, &size);
4548

46-
if (!result)
49+
if (!result) {
4750
throw exception(error_code::k_failed_converting_bson_to_json);
51+
}
4852

4953
const auto deleter = [](char* result) { bson_free(result); };
5054
const std::unique_ptr<char[], decltype(deleter)> cleanup(result, deleter);

0 commit comments

Comments
 (0)