Skip to content

Commit 33ca341

Browse files
committed
CDRIVER-643: Fix 'format ‘%ld’ expects argument of type ‘long int’, but argument 5 has type ‘ssize_t’'
1 parent 38ae108 commit 33ca341

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

tests/TestSuite.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ extern "C" {
7171
#define ASSERT_CMPULONG(a, eq, b) ASSERT_CMPINT_HELPER(a, eq, b, "lu")
7272
#define ASSERT_CMPINT64(a, eq, b) ASSERT_CMPINT_HELPER(a, eq, b, PRId64)
7373
#define ASSERT_CMPUINT64(a, eq, b) ASSERT_CMPINT_HELPER(a, eq, b, PRIu64)
74+
#define ASSERT_CMPSIZE_T(a, eq, b) ASSERT_CMPINT_HELPER(a, eq, b, "zd")
75+
#define ASSERT_CMPSSIZE_T(a, eq, b) ASSERT_CMPINT_HELPER(a, eq, b, "zx")
7476

7577
#define ASSERT_MEMCMP(a, b, n) \
7678
do { \

tests/test-mongoc-gridfs.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ test_read (void)
316316
char buf[10], buf2[10];
317317
mongoc_iovec_t iov[2];
318318
int previous_errno;
319+
ssize_t twenty = 20L;
319320

320321
iov[0].iov_base = buf;
321322
iov[0].iov_len = 10;
@@ -337,21 +338,21 @@ test_read (void)
337338
ASSERT (mongoc_gridfs_file_save (file));
338339

339340
r = mongoc_gridfs_file_readv (file, iov, 2, 20, 0);
340-
ASSERT_CMPLONG (r, ==, 20L);
341+
ASSERT_CMPSSIZE_T (r, ==, twenty);
341342
ASSERT_MEMCMP (iov[0].iov_base, "Bacon ipsu", 10);
342343
ASSERT_MEMCMP (iov[1].iov_base, "m dolor si", 10);
343344

344345
ASSERT_CMPINT (mongoc_gridfs_file_seek (file, 1, SEEK_SET), ==, 0);
345346
r = mongoc_gridfs_file_readv (file, iov, 2, 20, 0);
346347

347-
ASSERT_CMPLONG (r, ==, 20L);
348+
ASSERT_CMPSSIZE_T (r, ==, twenty);
348349
ASSERT_MEMCMP (iov[0].iov_base, "acon ipsum", 10);
349350
ASSERT_MEMCMP (iov[1].iov_base, " dolor sit", 10);
350351

351352
ASSERT_CMPINT (mongoc_gridfs_file_seek (file, file->chunk_size-1, SEEK_SET), ==, 0);
352353
r = mongoc_gridfs_file_readv (file, iov, 2, 20, 0);
353354

354-
ASSERT_CMPLONG (r, ==, 20L);
355+
ASSERT_CMPSSIZE_T (r, ==, twenty);
355356
ASSERT_CMPINT64 (mongoc_gridfs_file_tell (file), ==, (uint64_t)(file->chunk_size+19));
356357
ASSERT_MEMCMP (iov[0].iov_base, "turducken ", 10);
357358
ASSERT_MEMCMP (iov[1].iov_base, "spare ribs", 10);
@@ -411,27 +412,27 @@ test_write (void)
411412

412413
/* Test a write across many pages */
413414
r = mongoc_gridfs_file_writev (file, iov, 2, 0);
414-
ASSERT_CMPLONG (r, ==, len);
415+
ASSERT_CMPSSIZE_T (r, ==, len);
415416

416417
ASSERT_CMPINT (mongoc_gridfs_file_seek (file, 0, SEEK_SET), ==, 0);
417418
ASSERT_CMPUINT64 (mongoc_gridfs_file_tell (file), ==, (uint64_t)0);
418419

419420
r = mongoc_gridfs_file_readv (file, &riov, 1, len, 0);
420-
ASSERT_CMPLONG (r, ==, len);
421+
ASSERT_CMPSSIZE_T (r, ==, len);
421422
ASSERT_CMPINT (memcmp (buf3, "foo bar baz", len), ==, 0);
422423

423424
/* Test a write starting and ending exactly on chunk boundaries */
424425
ASSERT_CMPINT (mongoc_gridfs_file_seek (file, file->chunk_size, SEEK_SET), ==, 0);
425426
ASSERT_CMPUINT64 (mongoc_gridfs_file_tell (file), ==, (uint64_t)(file->chunk_size));
426427

427428
r = mongoc_gridfs_file_writev (file, iov+1, 1, 0);
428-
ASSERT_CMPLONG (r, ==, iov[1].iov_len);
429+
ASSERT_CMPSSIZE_T (r, ==, iov[1].iov_len);
429430

430431
ASSERT_CMPINT (mongoc_gridfs_file_seek (file, 0, SEEK_SET), ==, 0);
431432
ASSERT_CMPUINT64 (mongoc_gridfs_file_tell (file), ==, (uint64_t)0);
432433

433434
r = mongoc_gridfs_file_readv (file, &riov, 1, len, 0);
434-
ASSERT_CMPLONG (r, ==, len);
435+
ASSERT_CMPSSIZE_T (r, ==, len);
435436
ASSERT_CMPINT (memcmp (buf3, "fo bazr baz", len), ==, 0);
436437

437438
/* Test writing beyond the end of the file */
@@ -472,6 +473,7 @@ test_empty (void)
472473
ssize_t r;
473474
char buf[2] = {'h', 'i'};
474475
mongoc_iovec_t iov[1];
476+
ssize_t two = 2L;
475477

476478
iov[0].iov_base = buf;
477479
iov[0].iov_len = 2;
@@ -496,13 +498,13 @@ test_empty (void)
496498

497499
r = mongoc_gridfs_file_writev(file, iov, 1, 0);
498500

499-
ASSERT_CMPLONG (r, ==, 2L);
501+
ASSERT_CMPSSIZE_T (r, ==, two);
500502
ASSERT_CMPINT (mongoc_gridfs_file_seek (file, 0, SEEK_SET), ==, 0);
501503
ASSERT_CMPUINT64 (mongoc_gridfs_file_tell (file), ==, (uint64_t)0);
502504

503505
r = mongoc_gridfs_file_readv(file, iov, 1, 2, 0);
504506

505-
ASSERT_CMPLONG (r, ==, 2L);
507+
ASSERT_CMPSSIZE_T (r, ==, two);
506508
ASSERT_CMPINT (strncmp (buf, "hi", 2), ==, 0);
507509

508510
mongoc_gridfs_file_destroy (file);
@@ -595,7 +597,7 @@ test_long_seek (void)
595597
written = 0;
596598
while (written < 20 * 1024 * 1024) {
597599
r = mongoc_gridfs_file_writev (file, &iov, 1, 0);
598-
ASSERT_CMPLONG (r, ==, buflen);
600+
ASSERT_CMPSSIZE_T (r, ==, buflen);
599601
written += r;
600602
}
601603

@@ -610,15 +612,15 @@ test_long_seek (void)
610612

611613
/* read the start of the file */
612614
r = mongoc_gridfs_file_readv (file, &iov, 1, sizeof (buf), 0);
613-
ASSERT_CMPLONG (r, ==, buflen);
615+
ASSERT_CMPSSIZE_T (r, ==, buflen);
614616
ASSERT_TELL (file, (uint64_t) buflen);
615617
cursor_id = mongoc_cursor_get_id (file->cursor);
616618

617619
/* seek forward into next batch and read, gridfs advances cursor */
618620
i = mongoc_gridfs_file_seek (file, four_mb, SEEK_CUR);
619621
ASSERT_CMPINT (i, ==, 0);
620622
r = mongoc_gridfs_file_readv (file, &iov, 1, sizeof (buf), 0);
621-
ASSERT_CMPLONG (r, ==, buflen);
623+
ASSERT_CMPSSIZE_T (r, ==, buflen);
622624
ASSERT_TELL (file, four_mb + 2 * buflen);
623625

624626
/* same as the cursor we started with */
@@ -629,7 +631,7 @@ test_long_seek (void)
629631
ASSERT_CMPINT (i, ==, 0);
630632
ASSERT_TELL (file, 4 * four_mb + 2 * buflen);
631633
r = mongoc_gridfs_file_readv (file, &iov, 1, sizeof (buf), 0);
632-
ASSERT_CMPLONG (r, ==, buflen);
634+
ASSERT_CMPSSIZE_T (r, ==, buflen);
633635
ASSERT_TELL (file, 4 * four_mb + 3 * buflen);
634636

635637
/* new cursor, not the one we started with */
@@ -718,7 +720,7 @@ test_missing_chunk (void)
718720
written = 0;
719721
while (written < 700 * 1024) {
720722
r = mongoc_gridfs_file_writev (file, &iov, 1, 0);
721-
ASSERT_CMPLONG (r, ==, buflen);
723+
ASSERT_CMPSSIZE_T (r, ==, buflen);
722724
written += r;
723725
}
724726

@@ -739,7 +741,7 @@ test_missing_chunk (void)
739741
for (;;) {
740742
r = mongoc_gridfs_file_readv (file, &iov, 1, sizeof (buf), 0);
741743
if (r > 0) {
742-
ASSERT_CMPLONG (r, ==, buflen);
744+
ASSERT_CMPSSIZE_T (r, ==, buflen);
743745
} else {
744746
ASSERT (mongoc_gridfs_file_error (file, &error));
745747
ASSERT_ERROR_CONTAINS (error,

0 commit comments

Comments
 (0)