Skip to content

Wrong parsing of int64 values nearest of limit #3126

@gysevvlad

Description

@gysevvlad

What is the issue you have?

For number "9223372036854775808" (int64_t::max() + 1) I expects that json.get<nlohmann::json::number_integer_t>() throws exception.

Can you provide a small but working code example?

https://godbolt.org/z/v4ejoPszf

#include "nlohmann/json.hpp"
#include <iostream>

int main(int, char **) {
  auto json = nlohmann::json::parse(R"({ "package size": 9223372036854775808 })");
  auto [key, number] = *json.items().begin();
  std::cout << number.get<nlohmann::json::number_integer_t>() << std::endl;
  return 0;
}

What is the expected behavior?

I expects to get exception.

And what is the actual behavior instead?

Program stdout
-9223372036854775808

Which compiler and operating system are you using?

  • Compiler: clang-12
  • Operating system: Ubuntu, RedHat

Which version of the library did you use?

  • latest release version 3.10.4
  • other release - please state the version: ___
  • the develop branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions