Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d64e86b

Browse files
Fix container-overflow AddressSanitizer warning in GridFS test code (#1431)
1 parent 743ec99 commit d64e86b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

‎src/mongocxx/test/v_noabi/gridfs/bucket.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <cstdlib>
2121
#include <fstream>
2222
#include <functional>
23+
#include <memory>
2324
#include <numeric>
2425
#include <sstream>
2526
#include <vector>
@@ -525,22 +526,21 @@ TEST_CASE("mongocxx::gridfs::downloader::read with arbitrary sizes", "[gridfs::d
525526
std::int32_t read_size = 0;
526527

527528
auto run_test = [&]() {
528-
REQUIRE(read_size != 0);
529+
REQUIRE(read_size > 0);
529530

530531
bsoncxx::types::bson_value::view id{bsoncxx::types::b_oid{bsoncxx::oid{}}};
531532
std::vector<std::uint8_t> expected = manual_gridfs_initialize(db, file_length, chunk_size, id);
532533

533534
// Allocate a buffer large enough to fit the data read from the downloader.
534-
std::vector<std::uint8_t> buffer;
535-
buffer.reserve(static_cast<std::size_t>(read_size));
535+
std::unique_ptr<std::uint8_t[]> buffer{new std::uint8_t[static_cast<std::size_t>(read_size)]};
536536

537537
std::size_t total_bytes_read = 0;
538538
auto downloader = bucket.open_download_stream(bsoncxx::types::bson_value::view{id});
539539

540-
while (std::size_t bytes_read = downloader.read(buffer.data(), static_cast<std::size_t>(read_size))) {
540+
while (std::size_t bytes_read = downloader.read(buffer.get(), static_cast<std::size_t>(read_size))) {
541541
std::vector<std::uint8_t> expected_bytes{
542542
expected.data() + total_bytes_read, expected.data() + total_bytes_read + bytes_read};
543-
std::vector<std::uint8_t> actual_bytes{buffer.data(), buffer.data() + bytes_read};
543+
std::vector<std::uint8_t> actual_bytes{buffer.get(), buffer.get() + bytes_read};
544544

545545
REQUIRE(expected_bytes == actual_bytes);
546546

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /