Skip to content

duration_to_sec_and_usec narrowing #1426

@stingray-11

Description

@stingray-11

This occurs with -Werror=conversion on a 32-bit Linux system (time_t is 32-bits) and GCC 10.

/home/user/andromeda-desktop-clients/build/_deps/cpp-httplib-build/out/httplib.h: In instantiation of 'void httplib::detail::duration_to_sec_and_usec(const T&, U) [with T = std::chrono::duration<long long int>; U = httplib::ClientImpl::set_read_timeout<long long int, std::ratio<1> >::<lambda(time_t, time_t)>]':
/home/user/andromeda-desktop-clients/build/_deps/cpp-httplib-build/out/httplib.h:1681:35:   required from 'void httplib::ClientImpl::set_read_timeout(const std::chrono::duration<_Rep1, _Period1>&) [with Rep = long long int; Period = std::ratio<1>]'
/home/user/andromeda-desktop-clients/build/_deps/cpp-httplib-build/out/httplib.h:1701:25:   required from 'void httplib::Client::set_read_timeout(const std::chrono::duration<_Rep1, _Period1>&) [with Rep = long long int; Period = std::ratio<1>]'
/home/user/andromeda-desktop-clients/src/lib/andromeda/HTTPRunner.cpp:19:54:   required from here
/home/user/andromeda-desktop-clients/build/_deps/cpp-httplib-build/out/httplib.h:1536:12: error: conversion from 'long long int' to 'time_t' {aka 'long int'} may change value [-Werror=conversion]
 1536 |   callback(sec, usec);
      |            ^~~

I'm calling set_read_timeout(std::chrono::seconds(120)) in my code. It looks like the std::chrono Rep is a long long int (64-bits) and httplib is assigning it to a time_t (32-bits). Probably will need a static_cast<time_t> somewhere as long as that yields the correct behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions