Fixed some issue with http_helpers while building in GCC 12.x#1742
Fixed some issue with http_helpers while building in GCC 12.x#1742fborges22 wants to merge 3 commits intomicrosoft:masterfrom
Conversation
| sprintf_s(buffer, sizeof(buffer), "%8IX", bytes_read); | ||
| #else | ||
| snprintf(buffer, sizeof(buffer), "%8zX", bytes_read); | ||
| snprintf(buffer, sizeof(buffer), "%08zx", bytes_read); |
There was a problem hiding this comment.
Because in GCC 12.x I am getting error messages while compiling the original cpprestsdk in Linux. And then, I refactored and made these changes.
There was a problem hiding this comment.
I am also using GCC 12.x, but the format string itself is not the issue for the string truncation warning. You're basically changing the behavior.
There was a problem hiding this comment.
While compiling the original sources, I am getting this error:
[ 1%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/client/http_client.cpp.o
[ 1%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/client/http_client_msg.cpp.o
[ 2%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/common/http_compression.cpp.o
[ 3%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/common/http_helpers.cpp.o
[ 3%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/common/http_msg.cpp.o
[ 4%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/listener/http_listener.cpp.o
[ 5%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/listener/http_server_api.cpp.o
[ 6%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/oauth/oauth1.cpp.o
[ 6%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/listener/http_listener_msg.cpp.o
[ 6%] Building CXX object Release/src/CMakeFiles/cpprest.dir/utilities/web_utilities.cpp.o
[ 7%] Building CXX object Release/src/CMakeFiles/cpprest.dir/utilities/asyncrt_utils.cpp.o
[ 9%] Building CXX object Release/src/CMakeFiles/cpprest.dir/utilities/base64.cpp.o
[ 9%] Building CXX object Release/src/CMakeFiles/cpprest.dir/websockets/client/ws_msg.cpp.o
[ 10%] Building CXX object Release/src/CMakeFiles/cpprest.dir/websockets/client/ws_client.cpp.o
[ 10%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/oauth/oauth2.cpp.o
[ 10%] Building CXX object Release/src/CMakeFiles/cpprest.dir/websockets/client/ws_client_wspp.cpp.o
[ 12%] Building CXX object Release/src/CMakeFiles/cpprest.dir/pplx/pplxlinux.cpp.o
[ 12%] Building CXX object Release/src/CMakeFiles/cpprest.dir/json/json.cpp.o
[ 13%] Building CXX object Release/src/CMakeFiles/cpprest.dir/json/json_parsing.cpp.o
[ 14%] Building CXX object Release/src/CMakeFiles/cpprest.dir/pplx/pplx.cpp.o
[ 14%] Building CXX object Release/src/CMakeFiles/cpprest.dir/uri/uri_builder.cpp.o
[ 15%] Building CXX object Release/src/CMakeFiles/cpprest.dir/uri/uri.cpp.o
[ 15%] Building CXX object Release/src/CMakeFiles/cpprest.dir/json/json_serialization.cpp.o
[ 15%] Building CXX object Release/src/CMakeFiles/cpprest.dir/pplx/threadpool.cpp.o
[ 16%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/client/http_client_asio.cpp.o
[ 16%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/client/x509_cert_utilities.cpp.o
[ 17%] Building CXX object Release/src/CMakeFiles/cpprest.dir/streams/fileio_posix.cpp.o
[ 18%] Building CXX object Release/src/CMakeFiles/cpprest.dir/http/listener/http_server_asio.cpp.o
/home/fborges/cpprestsdk/Release/src/http/common/http_helpers.cpp: In function ‘size_t web::http::details::chunked_encoding::add_chunked_delimiters(uint8_t*, size_t, size_t)’:
/home/fborges/cpprestsdk/Release/src/http/common/http_helpers.cpp:91:43: error: ‘%8zX’ directive output may be truncated writing between 8 and 16 bytes into a region of size 9 [-Werror=format-truncation=]
91 | snprintf(buffer, sizeof(buffer), "%8zX", bytes_read);
| ^~~~
/home/fborges/cpprestsdk/Release/src/http/common/http_helpers.cpp:91:42: note: directive argument in the range [1, 18446744073709551615]
91 | snprintf(buffer, sizeof(buffer), "%8zX", bytes_read);
| ^~~~~~
/home/fborges/cpprestsdk/Release/src/http/common/http_helpers.cpp:91:17: note: ‘snprintf’ output between 9 and 17 bytes into a destination of size 9
91 | snprintf(buffer, sizeof(buffer), "%8zX", bytes_read);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
make[2]: *** [Release/src/CMakeFiles/cpprest.dir/build.make:118: Release/src/CMakeFiles/cpprest.dir/http/common/http_helpers.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /usr/include/boost/smart_ptr/detail/sp_thread_sleep.hpp:22,
from /usr/include/boost/smart_ptr/detail/yield_k.hpp:23,
from /usr/include/boost/smart_ptr/detail/spinlock_gcc_atomic.hpp:14,
from /usr/include/boost/smart_ptr/detail/spinlock.hpp:42,
from /usr/include/boost/smart_ptr/detail/spinlock_pool.hpp:25,
from /usr/include/boost/smart_ptr/shared_ptr.hpp:29,
from /usr/include/boost/shared_ptr.hpp:17,
from /usr/include/boost/date_time/time_clock.hpp:17,
from /usr/include/boost/thread/thread_time.hpp:9,
from /usr/include/boost/thread/detail/platform_time.hpp:11,
from /usr/include/boost/thread/pthread/condition_variable.hpp:9,
from /usr/include/boost/thread/condition_variable.hpp:16,
from /home/fborges/cpprestsdk/Release/src/pch/stdafx.h:61,
from /home/fborges/cpprestsdk/Release/src/http/client/http_client_asio.cpp:16:
/usr/include/boost/bind.hpp:36:1: note: ‘#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.’
36 | BOOST_PRAGMA_MESSAGE(
| ^~~~~~~~~~~~~~~~~~~~
make[1]: *** [CMakeFiles/Makefile2:545: Release/src/CMakeFiles/cpprest.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
There was a problem hiding this comment.
The cause of the issue is not the format string, it is the buffer size that may force a snprintf truncation.
There was a problem hiding this comment.
Okay, I am going to increase the buffer size and commit again.
Thanks :D |
|
Same as #1462, which was never merged, so I wouldn't put my hopes too high :-( |
Fixed to build in GCC 12.x and it is working in my environment.