Skip to content

Commit

Permalink
CDRIVER-4789 libbson: prevent -Werror=conversion with GCC 12 (#1479)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
rohieb committed Nov 29, 2023
1 parent 9e6a816 commit 5e27ad6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/libbson/NEWS
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
libbson 1.25.2 (Unreleased)
===========================

TODO: Add news.
Fixes:

* Fix conversion warning with GCC 12.

libbson 1.25.1
==============
Expand Down
5 changes: 3 additions & 2 deletions src/libbson/src/bson/bson-iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,11 @@ bson_iter_timeval_unsafe (const bson_iter_t *iter, struct timeval *tv)
int64_t value = bson_iter_int64_unsafe (iter);
#ifdef BSON_OS_WIN32
tv->tv_sec = (long) (value / 1000);
tv->tv_usec = (long) (value % 1000) * 1000;
#else
tv->tv_sec = (suseconds_t) (value / 1000);
tv->tv_sec = (time_t) (value / 1000);
tv->tv_usec = (suseconds_t) (value % 1000) * 1000;
#endif
tv->tv_usec = (value % 1000) * 1000;
}


Expand Down

0 comments on commit 5e27ad6

Please sign in to comment.