Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the -fstack-protector warning #4273

Closed
wants to merge 2 commits into from
Closed

Conversation

ZhksB
Copy link

@ZhksB ZhksB commented Jan 25, 2024

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 lines 1553, 1558 and 1563.

Example:
main.cpp

#include <nlohmann/json.hpp>
using json = nlohmann::json;

int main()
{
    json ex1 = json::parse(R"(
    {
        "pi": 3.141,
        "happy": true
    })");
   return 0;
}

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.

@github-actions github-actions bot added the M label Jan 25, 2024
@coveralls
Copy link

Coverage Status

coverage: 100.0%. remained the same
when pulling 7daa367 on ZhksB:develop
into 7efe875 on nlohmann:develop.

Copy link

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated. @ZhksB
Please read and follow the Contribution Guidelines.

@nlohmann
Copy link
Owner

What's wrong with setting --param ssp-buffer-size=4?

@ZhksB
Copy link
Author

ZhksB commented Jan 28, 2024

What's wrong with setting --param ssp-buffer-size=4?

I didn't change it.
I have the error with make amalgamation on Fedora and for this reason I cannot finish the PR. I will try to make an update using a different OS.

@nlohmann
Copy link
Owner

What's wrong with setting --param ssp-buffer-size=4?

I didn't change it.

I meant: why do you want to change the (correct) sizes in the library code when you can use the parameter above to suppress the warning?

I have the error with make amalgamation on Fedora and for this reason I cannot finish the PR. I will try to make an update using a different OS.

Please see #4275.

@ZhksB
Copy link
Author

ZhksB commented Jan 28, 2024

I meant: why do you want to change the (correct) sizes in the library code when you can use the parameter above to suppress the warning?

I will check. If it works, then there is no sense to change the array size.

@ZhksB
Copy link
Author

ZhksB commented Jan 29, 2024

What's wrong with setting --param ssp-buffer-size=4?

I made the tests and this param works for me. There is no sense in PR more, and I close it.

@ZhksB ZhksB closed this Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants