Stack overflow when printing double
Created by: miloyip
When printing large/small double
s, using %f
will generate very long output and generate stack overflow, as shown in the following debug section:
frame #4: 0x0000000100006361 nativejson_debug_x64_gmake`Print::print(this=0x00007fff5fbfe5c0, value=1.7976931348623157E+308, digits=20) + 129 at Print.cpp:24
21 size_t Print::print(double value, int digits) {
22 char tmp[32];
23 sprintf(tmp, "%.*f", digits, value);
-> 24 return print(tmp);
25 }
26
27 size_t Print::print(long value) {
(lldb) p tmp
(char [32]) $0 = "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00000000000000000000
I think a suitable format should be %.*g
, though the meaning of digits
are not the same.