mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-25 21:41:03 +00:00
- hotfix for a RapidJSON bug: If the Writer tries to process an INF or NaN value, it aborts and leaves the writer in a broken state, unable to recover. Changed so that it writes a 0 value so that the resulting JSON at least parses correctly.
This commit is contained in:
parent
3418710a38
commit
37d61167ea
2 changed files with 27 additions and 19 deletions
|
@ -322,8 +322,15 @@ protected:
|
||||||
|
|
||||||
bool WriteDouble(double d) {
|
bool WriteDouble(double d) {
|
||||||
if (internal::Double(d).IsNanOrInf()) {
|
if (internal::Double(d).IsNanOrInf()) {
|
||||||
|
bool ret = true;
|
||||||
if (!(writeFlags & kWriteNanAndInfFlag))
|
if (!(writeFlags & kWriteNanAndInfFlag))
|
||||||
return false;
|
{
|
||||||
|
// if we abort here, the writer is left in a broken state, unable to recover, so better write a 0 in addition to returning an error.
|
||||||
|
ret = false;
|
||||||
|
d = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (internal::Double(d).IsNan()) {
|
if (internal::Double(d).IsNan()) {
|
||||||
PutReserve(*os_, 3);
|
PutReserve(*os_, 3);
|
||||||
PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
|
PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
|
||||||
|
@ -339,13 +346,14 @@ protected:
|
||||||
PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
|
PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char buffer[25];
|
char buffer[25];
|
||||||
char* end = internal::dtoa(d, buffer, maxDecimalPlaces_);
|
char* end = internal::dtoa(d, buffer, maxDecimalPlaces_);
|
||||||
PutReserve(*os_, static_cast<size_t>(end - buffer));
|
PutReserve(*os_, static_cast<size_t>(end - buffer));
|
||||||
for (char* p = buffer; p != end; ++p)
|
for (char* p = buffer; p != end; ++p)
|
||||||
PutUnsafe(*os_, static_cast<typename TargetEncoding::Ch>(*p));
|
PutUnsafe(*os_, static_cast<typename TargetEncoding::Ch>(*p));
|
||||||
return true;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteString(const Ch* str, SizeType length) {
|
bool WriteString(const Ch* str, SizeType length) {
|
||||||
|
|
|
@ -217,11 +217,11 @@ struct FWriter
|
||||||
{
|
{
|
||||||
if (mWriter1)
|
if (mWriter1)
|
||||||
{
|
{
|
||||||
if (!mWriter1->Double(k)) mWriter1->Double(0);
|
mWriter1->Double(k);
|
||||||
}
|
}
|
||||||
else if (mWriter2)
|
else if (mWriter2)
|
||||||
{
|
{
|
||||||
if (!mWriter2->Double(k)) mWriter2->Double(0);
|
mWriter2->Double(k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue