Merge pull request #328 from Vhuynh25/master

Ignore NaN and infinite values in json::wvalue
This commit is contained in:
Farook Al-Sammarraie 2022-02-09 13:27:04 +03:00 committed by GitHub
commit e8e46266b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,9 +16,11 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/operators.hpp>
#include <vector>
#include <math.h>
#include "crow/settings.h"
#include "crow/returnable.h"
#include "crow/logging.h"
#if defined(__GNUG__) || defined(__clang__)
#define crow_json_likely(x) __builtin_expect(x, 1)
@ -1772,6 +1774,12 @@ namespace crow
{
if (v.nt == num_type::Floating_point)
{
if (isnan(v.num.d) || isinf(v.num.d))
{
out += "null";
CROW_LOG_WARNING << "Invalid JSON value detected (" << v.num.d << "), value set to null";
break;
}
#ifdef _MSC_VER
#define MSC_COMPATIBLE_SPRINTF(BUFFER_PTR, FORMAT_PTR, VALUE) sprintf_s((BUFFER_PTR), 128, (FORMAT_PTR), (VALUE))
#else