Skip to content
Myr

Fix dumping large floating numbers (fix #2367) (#2661)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by itchyny · committed by GitHub · parent c68ad08 · Browse files · 2 files+13 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−12 removed

  • tests:+6 added−0 removed
  • other:+7 added−12 removed

2 files+13 added−12 removed

modified:src/jv.c+7 added-12 removed
214 unmodified lines
215#define JVP_FLAGS_NUMBER_NATIVE JVP_MAKE_FLAGS(JV_KIND_NUMBER, JVP_MAKE_PFLAGS(JVP_NUMBER_NATIVE, 0))216#define JVP_FLAGS_NUMBER_NATIVE_STR JVP_MAKE_FLAGS(JV_KIND_NUMBER, JVP_MAKE_PFLAGS(JVP_NUMBER_NATIVE, 1))217#define JVP_FLAGS_NUMBER_LITERAL JVP_MAKE_FLAGS(JV_KIND_NUMBER, JVP_MAKE_PFLAGS(JVP_NUMBER_DECIMAL, 1))218219#define STR(x) #x220#define XSTR(x) STR(x)221#define DBL_MAX_STR XSTR(DBL_MAX)222#define DBL_MIN_STR "-" XSTR(DBL_MAX)223219// the decimal precision of binary double220#define BIN64_DEC_PRECISION (17)221#define DEC_NUMBER_STRING_GUARD (14)222228#include <jv_thread.h>223#include "jv_thread.h"224#ifdef WIN32225/* Copied from Heimdal: thread-specific keys; see lib/base/dll.c in Heimdal */226227/*
424 unmodified lines
652 return "null";653 }654655 if (decNumberIsInfinite(pdec)) {661 // For backward compatibility.662 if (decNumberIsNegative(pdec)) {663 return DBL_MIN_STR;664 } else {665 return DBL_MAX_STR;666 }656 // We cannot preserve the literal data of numbers outside the limited657 // range of exponent. Since `decNumberToString` returns "Infinity"658 // (or "-Infinity"), and to reduce stack allocations as possible, we659 // normalize infinities in the callers instead of printing the maximum660 // (or minimum) double here.661 return NULL;662 }663664 if (plit->literal_data == NULL) {665 int len = jvp_dec_number_ptr(n)->digits + 14;
1322 unmodified lines
modified:tests/shtest+6 added
150 unmodified lines
151 echo "Invalid input had wrong error code" 1>&2152 exit 1153fi154155# Regression test for #2367; make sure to call jq twice156if ! echo '{"a": 1E9999999999}' | $JQ . | $JQ -e .a; then157 printf 'Issue #2367 is back?\n' 1>&2158 exit 1159fi160161# Regression test for #1534162echo "[1,2,3,4]" > $d/expected163printf "[1,2][3,4]" | $JQ -cs add > $d/out 2>&1164cmp $d/out $d/expected
217 unmodified lines