Skip to content

Fix cppcheck warning #4758

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Fix cppcheck warning #4758

wants to merge 2 commits into from

Conversation

nlohmann
Copy link
Owner

The serialization of floating-point numbers is handled in two code paths. If number_float_t is an IEEE-754 single or double precision number, the Grisu2 algorithm is used. Otherwise, the serialization is done via std::snprintf. By updating cppcheck to 1.5.1, it warns that the used specifier "%.*g" only works with double.

This PR adds a conversion to double in the std::snprintf call to silence this warning.

Closes #4755

Signed-off-by: Niels Lohmann <[email protected]>
@coveralls
Copy link

Coverage Status

coverage: 99.188%. remained the same
when pulling dfb9eb6 on issue4755-cppcheck-warning
into 51a77f1 on develop.

@nlohmann nlohmann marked this pull request as ready for review May 16, 2025 17:56
@nlohmann nlohmann added the review needed It would be great if someone could review the proposed changes. label May 16, 2025
@nlohmann nlohmann added this to the Release 3.12.1 milestone May 16, 2025
@github-actions github-actions bot added L and removed M labels May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CMake L review needed It would be great if someone could review the proposed changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix cppcheck 1.5.1 warning
3 participants