Fix the -fstack-protector warning #4273
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a warning appeared when the json library is compiled with -fstack-protector flag using g++ 11th version in Linux Fedora 37.
In our case it turns into error since we use -Werror flag.
The commit aims to fix the issue by adjusting the array size to 8 bytes in
lexer.hpp
in lines1553
,1558
and1563
.Example:
main.cpp
Build:
g++ main.cpp -o out -fstack-protector -Wstack-protector -I nlohmann/include
Output:
In file included from nlohmann/include/nlohmann/detail/input/binary_reader.hpp:27, from nlohmann/include/nlohmann/json.hpp:40, from main.cpp:1: nlohmann/include/nlohmann/detail/input/lexer.hpp: In member function 'nlohmann::json_abi_v3_11_3::detail::lexer<BasicJsonType, InputAdapterType>::token_type nlohmann::json_abi_v3_11_3::detail::lexer<BasicJsonType, InputAdapterType>::scan() [with BasicJsonType = nlohmann::json_abi_v3_11_3::basic_json<>; InputAdapterType = nlohmann::json_abi_v3_11_3::detail::iterator_input_adapter<const char*>]': nlohmann/include/nlohmann/detail/input/lexer.hpp:1510:16: warning: stack protector not protecting function: all local arrays are less than 8 bytes long [-Wstack-protector] token_type scan()
The PR fixes the warning.