1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

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

This commit is contained in:
itchyny
2023-07-06 21:44:17 +09:00
committed by GitHub
parent c68ad08805
commit 6944d81bc8
2 changed files with 13 additions and 12 deletions

View File

@@ -216,16 +216,11 @@ enum {
#define JVP_FLAGS_NUMBER_NATIVE_STR JVP_MAKE_FLAGS(JV_KIND_NUMBER, JVP_MAKE_PFLAGS(JVP_NUMBER_NATIVE, 1)) #define JVP_FLAGS_NUMBER_NATIVE_STR JVP_MAKE_FLAGS(JV_KIND_NUMBER, JVP_MAKE_PFLAGS(JVP_NUMBER_NATIVE, 1))
#define JVP_FLAGS_NUMBER_LITERAL JVP_MAKE_FLAGS(JV_KIND_NUMBER, JVP_MAKE_PFLAGS(JVP_NUMBER_DECIMAL, 1)) #define JVP_FLAGS_NUMBER_LITERAL JVP_MAKE_FLAGS(JV_KIND_NUMBER, JVP_MAKE_PFLAGS(JVP_NUMBER_DECIMAL, 1))
#define STR(x) #x
#define XSTR(x) STR(x)
#define DBL_MAX_STR XSTR(DBL_MAX)
#define DBL_MIN_STR "-" XSTR(DBL_MAX)
// the decimal precision of binary double // the decimal precision of binary double
#define BIN64_DEC_PRECISION (17) #define BIN64_DEC_PRECISION (17)
#define DEC_NUMBER_STRING_GUARD (14) #define DEC_NUMBER_STRING_GUARD (14)
#include <jv_thread.h> #include "jv_thread.h"
#ifdef WIN32 #ifdef WIN32
/* Copied from Heimdal: thread-specific keys; see lib/base/dll.c in Heimdal */ /* Copied from Heimdal: thread-specific keys; see lib/base/dll.c in Heimdal */
@@ -658,12 +653,12 @@ static const char* jvp_literal_number_literal(jv n) {
} }
if (decNumberIsInfinite(pdec)) { if (decNumberIsInfinite(pdec)) {
// For backward compatibility. // We cannot preserve the literal data of numbers outside the limited
if (decNumberIsNegative(pdec)) { // range of exponent. Since `decNumberToString` returns "Infinity"
return DBL_MIN_STR; // (or "-Infinity"), and to reduce stack allocations as possible, we
} else { // normalize infinities in the callers instead of printing the maximum
return DBL_MAX_STR; // (or minimum) double here.
} return NULL;
} }
if (plit->literal_data == NULL) { if (plit->literal_data == NULL) {

View File

@@ -152,6 +152,12 @@ elif [ $? -ne 5 ]; then
exit 1 exit 1
fi fi
# Regression test for #2367; make sure to call jq twice
if ! echo '{"a": 1E9999999999}' | $JQ . | $JQ -e .a; then
printf 'Issue #2367 is back?\n' 1>&2
exit 1
fi
# Regression test for #1534 # Regression test for #1534
echo "[1,2,3,4]" > $d/expected echo "[1,2,3,4]" > $d/expected
printf "[1,2][3,4]" | $JQ -cs add > $d/out 2>&1 printf "[1,2][3,4]" | $JQ -cs add > $d/out 2>&1