Skip to content

Incorrect parsing of large int64_t numbers #287

Closed

Description

@mariobadr

Hello,

I use dynamic instrumentation to gather information about a program, and then output it using your json library to a file. When I parse the file into a different application using your library, I get different values. Below is a minimal example:

main.cpp

#include <fstream>
#include <iostream>

#include "json.hpp"

int main(int argc, char** argv) {
  using json = nlohmann::json;

  if(argc != 2) {
    return 0;
  }

  std::ifstream stream(argv[1]);
  json j;
  stream >> j;

  std::cout << j["id"] << "\n";

  return 0;
}

test.json
{ "call": "pthread_mutex_lock", "id": 8492065431569638403, "object": 139898772169632 }

Output
8492065431569638400

The documentation states that numbers are stored in int64_t, and that the maximum value allowed is 9223372036854775807. The above value is less than that number, so I'm not sure what the problem is. Thanks.

Edit: I am using version 1.1.0

Activity

  1. mariobadr commented on Aug 2, 2016

    @mariobadr
    Author

    Sorry, just noticed #178/#183 and tried out version 2.0.2 and everything works fine now. Thanks for the awesome library!

  2. added
    solution: invalid
    on Aug 2, 2016
  3. nlohmann commented on Aug 2, 2016

    @nlohmann
    Owner

    No worries! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: invalid

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions