libcpr / cpr

C++ Requests: Curl for People, a spiritual port of Python Requests.
https://docs.libcpr.org/
Other
6.55k stars 933 forks source link

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]` #1087

Closed barracuda156 closed 1 month ago

barracuda156 commented 3 months ago

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

COM8 commented 2 months ago

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

COM8 commented 2 months ago

Fixed in https://github.com/libcpr/cpr/pull/1097. Can you confirm?

barracuda156 commented 5 days ago

@COM8 Yes, 1.11.0 builds fine. (Sorry for a delayed reply.)

COM8 commented 5 days ago

Awesome. Thanks for the update.