libcpr/cpr

Build failure: `httpServer.cpp: error: overflow in conversion from 'long long int' to 'time_t' {aka 'long int'} changes value from '3905119080' to '-389848216' [-Werror=overflow]`

Closed this issue · 2 comments

Description

Build fails on 32-bit arch due to overflow caused by 32-bit time_t:

[ 37%] Building CXX object test/CMakeFiles/test_server.dir/httpServer.cpp.o
cd /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/build/test && /opt/local/bin/ccache /opt/local/bin/g++-mp-14 -DCPR_BUILD_TESTS -DCPR_BUILD_TESTS_SSL -DCPR_ENABLE_CURL_HTTP_ONLY -DCPR_ENABLE_SSL -DCPR_FORCE_OPENSSL_BACKEND -DCPR_USE_SYSTEM_CURL -DCPR_USE_SYSTEM_GTEST -DMG_ENABLE_OPENSSL -DOPENSSL_BACKEND_USED -I/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/cpr-1.10.5/include -I/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/build/cpr_generated_includes -I/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/build/_deps/mongoose-src -isystem /opt/local/include -pipe -I/opt/local/libexec/openssl3/include -Os -DNDEBUG -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -D_GLIBCXX_USE_CXX11_ABI=0 -Wall -Wextra -Wpedantic -Werror -std=gnu++17 -arch ppc -mmacosx-version-min=10.6 -MD -MT test/CMakeFiles/test_server.dir/httpServer.cpp.o -MF CMakeFiles/test_server.dir/httpServer.cpp.o.d -o CMakeFiles/test_server.dir/httpServer.cpp.o -c /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/cpr-1.10.5/test/httpServer.cpp
[ 38%] Building CXX object test/CMakeFiles/test_server.dir/httpsServer.cpp.o
cd /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/build/test && /opt/local/bin/ccache /opt/local/bin/g++-mp-14 -DCPR_BUILD_TESTS -DCPR_BUILD_TESTS_SSL -DCPR_ENABLE_CURL_HTTP_ONLY -DCPR_ENABLE_SSL -DCPR_FORCE_OPENSSL_BACKEND -DCPR_USE_SYSTEM_CURL -DCPR_USE_SYSTEM_GTEST -DMG_ENABLE_OPENSSL -DOPENSSL_BACKEND_USED -I/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/cpr-1.10.5/include -I/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/build/cpr_generated_includes -I/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/build/_deps/mongoose-src -isystem /opt/local/include -pipe -I/opt/local/libexec/openssl3/include -Os -DNDEBUG -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -D_GLIBCXX_USE_CXX11_ABI=0 -Wall -Wextra -Wpedantic -Werror -std=gnu++17 -arch ppc -mmacosx-version-min=10.6 -MD -MT test/CMakeFiles/test_server.dir/httpsServer.cpp.o -MF CMakeFiles/test_server.dir/httpsServer.cpp.o.d -o CMakeFiles/test_server.dir/httpsServer.cpp.o -c /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/cpr-1.10.5/test/httpsServer.cpp
[ 40%] Building CXX object test/CMakeFiles/test_server.dir/abstractServer.cpp.o
cd /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/build/test && /opt/local/bin/ccache /opt/local/bin/g++-mp-14 -DCPR_BUILD_TESTS -DCPR_BUILD_TESTS_SSL -DCPR_ENABLE_CURL_HTTP_ONLY -DCPR_ENABLE_SSL -DCPR_FORCE_OPENSSL_BACKEND -DCPR_USE_SYSTEM_CURL -DCPR_USE_SYSTEM_GTEST -DMG_ENABLE_OPENSSL -DOPENSSL_BACKEND_USED -I/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/cpr-1.10.5/include -I/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/build/cpr_generated_includes -I/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/build/_deps/mongoose-src -isystem /opt/local/include -pipe -I/opt/local/libexec/openssl3/include -Os -DNDEBUG -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -D_GLIBCXX_USE_CXX11_ABI=0 -Wall -Wextra -Wpedantic -Werror -std=gnu++17 -arch ppc -mmacosx-version-min=10.6 -MD -MT test/CMakeFiles/test_server.dir/abstractServer.cpp.o -MF CMakeFiles/test_server.dir/abstractServer.cpp.o.d -o CMakeFiles/test_server.dir/abstractServer.cpp.o -c /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/cpr-1.10.5/test/abstractServer.cpp
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/cpr-1.10.5/test/httpServer.cpp: In static member function 'static void cpr::HttpServer::OnRequestBasicCookies(mg_connection*, mg_http_message*)':
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/cpr-1.10.5/test/httpServer.cpp:145:27: error: overflow in conversion from 'long long int' to 'time_t' {aka 'long int'} changes value from '3905119080' to '-389848216' [-Werror=overflow]
  145 |     time_t expires_time = 3905119080; // Expires=Wed, 30 Sep 2093 03:18:00 GMT
      |                           ^~~~~~~~~~
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/cpr-1.10.5/test/httpServer.cpp: In static member function 'static void cpr::HttpServer::OnRequestEmptyCookies(mg_connection*, mg_http_message*)':
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/cpr-1.10.5/test/httpServer.cpp:164:27: error: overflow in conversion from 'long long int' to 'time_t' {aka 'long int'} changes value from '3905119080' to '-389848216' [-Werror=overflow]
  164 |     time_t expires_time = 3905119080; // Expires=Wed, 30 Sep 2093 03:18:00 GMT
      |                           ^~~~~~~~~~
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/cpr-1.10.5/test/httpServer.cpp: In static member function 'static void cpr::HttpServer::OnRequestRedirectionWithChangingCookies(mg_connection*, mg_http_message*)':
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_devel_cpr/cpr/work/cpr-1.10.5/test/httpServer.cpp:195:27: error: overflow in conversion from 'long long int' to 'time_t' {aka 'long int'} changes value from '3905119080' to '-389848216' [-Werror=overflow]
  195 |     time_t expires_time = 3905119080; // Expires=Wed, 30 Sep 2093 03:18:00 GMT
      |                           ^~~~~~~~~~
cc1plus: all warnings being treated as errors
make[2]: *** [test/CMakeFiles/test_server.dir/httpServer.cpp.o] Error 1

Example/How to Reproduce

Build on a 32-bit platform

Possible Fix

Instead of relying on the OS-provided time_t, 64-bit types should be used consistently.

Where did you get it from?

GitHub (branch e.g. master)

Additional Context/Your Environment

  • OS: macOS
  • Version: 10.6 / ppc
COM8 commented

One workaround would be to build without tests (-DCPR_BUILD_TESTS=OFF). But in parallel I'm looking into it.

COM8 commented

Fixed in #1097. Can you confirm?