Skip to content

fix: integer parsed as float when EINTR set in errno #4506

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

Merged

Conversation

StuartGorman
Copy link
Contributor

Problem: Occasionally the OS will set errno to EINTR if some system call has been interrupted. If that happens in lexer:scan_number() it will be treated the same as errno being set to ERANGE due to the check being errno == 0. This will cause valid integers to be parsed as floats.

Fix: Changing the errno check to explicitly check for ERANGE, as that is the condition that the parsing code cares about.

Environment:

  • gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
  • cmake version 3.26.3

Pull request checklist

Read the Contribution Guidelines for detailed information.

  • Changes are described in the pull request, or an existing issue is referenced.
  • The test suite compiles and runs without error.
  • Code coverage is 100%. Test cases can be added by editing the test suite.
  • The source code is amalgamated; that is, after making changes to the sources in the include/nlohmann directory, run make amalgamate to create the single-header files single_include/nlohmann/json.hpp and single_include/nlohmann/json_fwd.hpp. The whole process is described here.

@github-actions github-actions bot added the L label Nov 21, 2024
@nlohmann
Copy link
Owner

Please run the amalgamation with astyle 3.1.

Copy link

🔴 Amalgamation check failed! 🔴

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

@coveralls
Copy link

coveralls commented Nov 21, 2024

Coverage Status

coverage: 100.0%. remained the same
when pulling 69c9fe0 on StuartGorman:bugfix/errno_restrict_to_erange
into 378e091 on nlohmann:develop.

@github-actions github-actions bot added S and removed L labels Nov 21, 2024
Copy link
Owner

@nlohmann nlohmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@nlohmann nlohmann added this to the Release 3.11.4 milestone Nov 21, 2024
@nlohmann nlohmann merged commit f9f8c07 into nlohmann:develop Nov 21, 2024
128 checks passed
@nlohmann
Copy link
Owner

Thanks!

@StuartGorman StuartGorman deleted the bugfix/errno_restrict_to_erange branch November 21, 2024 22:50
slowriot pushed a commit to slowriot/json that referenced this pull request Jan 10, 2025
* fix: integer parsed as float when EINTR set in errno

* chore: make amalgamate

* chore: make pretty

---------

Co-authored-by: Stuart Gorman <Stuart.Gorman@kallipr.com>
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