From 7affcfc02d565bfcfe63605d82578d45d44303d8 Mon Sep 17 00:00:00 2001 From: dongheng Date: Mon, 20 May 2019 10:39:17 +0800 Subject: [PATCH] feat(cjson): Check if 32-bit type data is overflow --- components/cjson/cJSON/cJSON.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/cjson/cJSON/cJSON.c b/components/cjson/cJSON/cJSON.c index cbc62a21..af1e4500 100644 --- a/components/cjson/cJSON/cJSON.c +++ b/components/cjson/cJSON/cJSON.c @@ -60,6 +60,10 @@ #define CJSON_SPRINTF_FLOAT 0 #endif +#if !CJSON_SPRINTF_FLOAT +#include +#endif + #include "cJSON.h" /* define our own boolean type */ @@ -510,8 +514,14 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out length = sprintf((char*)number_buffer, "%1.17g", d); } #else + long long d64 = (long long)d; long d32 = (long)d; + /** + * Check if 32-bit type data is overflow. + */ + assert(d32 == d64 && "Library newlib of nano mode does not support double or long-long format, please enable newlib normal mode."); + length = sprintf((char*)number_buffer, "%ld", d32); if ((double)d32 != d) {