From 95f120f68eee1215e17b6c4110553fdb6cb51f4d Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 7 Feb 2016 11:09:41 -0600 Subject: [PATCH] For gcc>=6 JSON_USE_INT64_DOUBLE_CONVERSION --- include/json/config.h | 4 ++++ src/lib_json/json_value.cpp | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/json/config.h b/include/json/config.h index 1b0581f..51027dd 100644 --- a/include/json/config.h +++ b/include/json/config.h @@ -114,6 +114,10 @@ #define JSONCPP_DEPRECATED(message) #endif // if !defined(JSONCPP_DEPRECATED) +#if __GNUC__ >= 6 +# define JSON_USE_INT64_DOUBLE_CONVERSION 1 +#endif + namespace Json { typedef int Int; typedef unsigned int UInt; diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index a1962e6..1f6425f 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -784,7 +784,8 @@ float Value::asFloat() const { #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) return static_cast(value_.uint_); #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - return integerToDouble(value_.uint_); + // This can fail (silently?) if the value is bigger than MAX_FLOAT. + return static_cast(integerToDouble(value_.uint_)); #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) case realValue: return static_cast(value_.real_);