Skip to content

Commit 57899f0

Browse files
committed
CDRIVER-1903 truly fix gridfs write test in MSVC
I had not known that _vsnprintf_s in debug mode fills the buffer out to "len" with 0xFE.
1 parent 883cc25 commit 57899f0

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

tests/test-mongoc-gridfs.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ _test_write (bool at_boundary)
532532
mongoc_iovec_t riov;
533533
ssize_t len = sizeof buf + sizeof buf2 - 2;
534534

535-
#ifndef _MSC_VER
536535
iov [0].iov_base = buf;
537536
iov [0].iov_len = sizeof (buf) - 1;
538537
iov [1].iov_base = buf2;
@@ -592,20 +591,13 @@ _test_write (bool at_boundary)
592591
assert (mongoc_gridfs_file_seek (file, 0, SEEK_SET) == 0);
593592
assert (mongoc_gridfs_file_tell (file) == 0);
594593

595-
/* necessary on MSVC, possibly because memcmp compares more bytes than the
596-
* provided length argument:
597-
* randomascii.wordpress.com/2012/10/31/comparing-memory-is-still-tricky
598-
*/
599-
memset (buf3, 0, sizeof (buf3));
600-
memset (expected, 0, sizeof (expected));
601-
602594
r = mongoc_gridfs_file_readv (file, &riov, 1, 2 * len + seek_len, 0);
603595
assert (r == 2 * len + seek_len);
604596

605597
/* expect file to be like "fo bazr baz\0\0\0\0\0\0foo bar baz" */
606-
bson_snprintf (expected, sizeof (expected), "fo bazr baz");
598+
bson_snprintf (expected, strlen ("fo bazr baz") + 1, "fo bazr baz");
607599
bson_snprintf (expected + strlen ("fo bazr baz") + seek_len,
608-
strlen ("foo bar baz") + 1, "foo bar baz");
600+
strlen ("foo bar baz") + 1,"foo bar baz");
609601

610602
assert (memcmp (buf3, expected, (size_t) (2 * len + seek_len)) == 0);
611603
assert (mongoc_gridfs_file_save (file));
@@ -616,7 +608,6 @@ _test_write (bool at_boundary)
616608
mongoc_gridfs_destroy (gridfs);
617609

618610
mongoc_client_destroy (client);
619-
#endif // _MSC_VER
620611
}
621612

622613

0 commit comments

Comments
 (0)