Skip to content

Serializing uint64_t is broken for large values #2578

@milasudril

Description

@milasudril

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: invalidthe issue is not related to the library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions