profile
viewpoint

Ask questionswrong output with int64_t writing

Hello, while investigating a crash I noticed that at some point one of my files got saved with the value : 9223372036854776000 for a call to Writer::Int64, which is necessarily a bug in the library as Int64 takes an int64_t as input, and 9223372036854776000 - (2^63-1) == 193 so not something representable.

Tencent/rapidjson

Answer questions miloyip

9223372036854776000 is larger than 2^63 -1 so it is not representable as int64_t. But it should not cause a crash.

#include "rapidjson/writer.h"
#include <iostream>

using namespace rapidjson;

int main() {
    StringBuffer sb;
    Writer<StringBuffer> writer(sb);
    writer.Int64(9223372036854776000LL);
    std::cout << sb.GetString();
}
g++ -std=c++11 -I ~/github/rapidjson/include -g a.cpp && ./a.out
a.cpp:9:18: warning: integer literal is too large to be represented in a signed integer type, interpreting as unsigned
      [-Wimplicitly-unsigned-literal]
    writer.Int64(9223372036854776000LL);
                 ^
1 warning generated.
-9223372036854775616
useful!

Related questions

是否支持流式解析以及多个json分离解析 hot 1
是否支持流式解析以及多个json分离解析 hot 1
RapidJSON causes cc1plus: internal compiler error: Segmentation fault - rapidjson hot 1
GenericMemberIterator::Iterator implicitly declared private when RAPIDJSON_NOMEMBERITERATORCLASS is defined hot 1
Always gets a core dump while creating json string (rapidjson) hot 1
Bazel Support hot 1
Syntax typo in tutorial hot 1
是否支持流式解析以及多个json分离解析 hot 1
作者你好,我 想请教一下,这个框架是否能够将变量中文stirng 转成wchar_t? 在文档只看到定量 hot 1
travis on windows hot 1
Added headers to my project and got thousands of errors hot 1
Added headers to my project and got thousands of errors hot 1
想要的反斜杠 \. 无法表示,否则JSON解析出错 hot 1
Assertion `stack_.GetSize() == sizeof(ValueType)' failed hot 1
source:https://uonfu.com/
Github User Rank List