boostorg / boostorg/boost

Boost json as_uint64() raise exception.

Open
#756 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
8.6k
Forks
1.9k
Avg merge
39m
Merged PRs (30d)
2

Description

Hello, I think I found the bug in `boost::json`.

```cpp
boost::json::object test;
test["quota"] = 12345;
std::string key("quota");
uint64_t quota;
try {
quota = test.at(key).as_uint64();
} catch(const std::out_of_range& e) {
std::cout << "Cannot found the key: <" << key << "> in Body!" << std::endl;
} catch(const std::invalid_argument& e) {
std::cout << "We found key: <" << key << "> in Body but it is " << e.what() << std::endl;
}
```

When I run above code, `std::invalid_argument` exception raised.

```bash
We found key: in Body but it is not a uint64
```

When I change `as_uint64()` to `as_int64()`, there is no raised exception. Is this bug? or my fault? Please guide me to solve this problem :(

\* Of course, I know the difference between uint64 and int64. But, I need `as_uint64()` for safe. (value should be larger than 0)

\** When I change the code 12345 to 12345UL, It works well without exception....

My enviornment is

- OS: CentOS 8 Stream
- G++: g++ (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
- Boost 1.80.0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.