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

Serializing uint64_t is broken for large values #2578

Closed
1 of 3 tasks
milasudril opened this issue Jan 9, 2021 · 3 comments
Closed
1 of 3 tasks

Serializing uint64_t is broken for large values #2578

milasudril opened this issue Jan 9, 2021 · 3 comments
Labels
solution: invalid the issue is not related to the library

Comments

@milasudril
Copy link

What is the issue you have?

The entire range of uint64_t cannot be serialized. This is a bug, because if the type is supported, then it should be supported completely.

Please describe the steps to reproduce the issue.

  1. Try to serialize a sufficiently large value

Can you provide a small but working code example?

set val = std::numeric_limits<uint64_t>::max() in the example below:

class NodeId
{
public:
	constexpr explicit NodeId(uint64_t val): m_value{val} {}

	constexpr NodeId(): m_value{0} {}

// other members

private:
	uint64_t m_value;
};

inline void to_json(nlohmann::json& obj, NodeId id) { obj = id.value(); }

What is the expected behavior?

If val = val = std::numeric_limits<uint64_t>::max() , then it should print 18446744073709551615, or a compilation error, that tells me that the type cannot be serialized.

And what is the actual behavior instead?

18446744073709552000 is the actual value.

Which compiler and operating system are you using?

  • Compiler: g++-10 (Ubuntu 10.2.0-5ubuntu1~20.04) 10.2.0
  • Operating system: Ubuntu 20.04.1 LTS
  • Architecture: x86-64

Which version of the library did you use?

  • latest release version 3.9.1
  • other release - please state the version: 3.7.3 (version packaged with the distro)
  • the develop branch

If you experience a compilation error: can you compile and run the unit tests? No compilation error

@milasudril
Copy link
Author

Maybe int64 should be serialized as a string instead?

@milasudril
Copy link
Author

Hmm, it actually is correct

@nlohmann
Copy link
Owner

I cannot reproduce this: https://godbolt.org/z/b5G5ae

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed kind: bug labels Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants