Skip to content

CDRIVER-4789 libbson: prevent -Werror=conversion with GCC 12 #1479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 29, 2023

Conversation

rohieb
Copy link
Contributor

@rohieb rohieb commented Nov 27, 2023

Building on ARM32 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.

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.
@kevinAlbs kevinAlbs self-requested a review November 27, 2023 19:55
This matches specificiation in POSIX 2008.
@kevinAlbs kevinAlbs requested a review from adriandole November 27, 2023 19:59
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @rohieb.

Applied c81e4ce to cast the assigned value to tv_sec to time_t to match what is specified in POSIX 2008: https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/

@kevinAlbs kevinAlbs changed the title libbson: prevent -Werror=conversion with GCC 12 CDRIVER-4789 libbson: prevent -Werror=conversion with GCC 12 Nov 27, 2023
@rohieb
Copy link
Contributor Author

rohieb commented Nov 27, 2023

Applied c81e4ce to cast the assigned value to tv_sec to time_t to match what is specified in POSIX 2008: https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/

Ah yes, thanks, looks correct to me!

@kevinAlbs kevinAlbs merged commit 5e27ad6 into mongodb:master Nov 29, 2023
kevinAlbs pushed a commit that referenced this pull request Nov 29, 2023
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants