Skip to content

Commit 5e27ad6

Browse files
authored
CDRIVER-4789 libbson: prevent -Werror=conversion with GCC 12 (#1479)
* libbson: prevent -Werror=conversion with GCC 12 Building fails with GCC 12.3: bson-iter.h:434:33: error: conversion from 'int64_t' {aka 'long long int'} to '__suseconds_t' {aka 'long int'} may change value [-Werror=conversion] 434 | tv->tv_usec = (value % 1000) * 1000; | ~~~~~~~~~~~~~~~^~~~~~ cc1plus: all warnings being treated as errors Do the same as with tv->tv_sec, and explicitely cast it to suseconds_t on non-Win32 systems and to long on Win32. * use `time_t` in assignment to `tv_sec` This matches specificiation in POSIX 2008.
1 parent 9e6a816 commit 5e27ad6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/libbson/NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
libbson 1.25.2 (Unreleased)
22
===========================
33

4-
TODO: Add news.
4+
Fixes:
5+
6+
* Fix conversion warning with GCC 12.
57

68
libbson 1.25.1
79
==============

src/libbson/src/bson/bson-iter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,11 @@ bson_iter_timeval_unsafe (const bson_iter_t *iter, struct timeval *tv)
440440
int64_t value = bson_iter_int64_unsafe (iter);
441441
#ifdef BSON_OS_WIN32
442442
tv->tv_sec = (long) (value / 1000);
443+
tv->tv_usec = (long) (value % 1000) * 1000;
443444
#else
444-
tv->tv_sec = (suseconds_t) (value / 1000);
445+
tv->tv_sec = (time_t) (value / 1000);
446+
tv->tv_usec = (suseconds_t) (value % 1000) * 1000;
445447
#endif
446-
tv->tv_usec = (value % 1000) * 1000;
447448
}
448449

449450

0 commit comments

Comments
 (0)