mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0029452: Application Framework - Failed to read an Ocaf XML document with 1.#QNAN value.
Method XmlObjMgt::GetReal() is improved to (a) recognize NAN and infinity written by old MSVC runtime (like 1.#QNAN and 1.#INF) and (b) detect situation when there are some trailing non-space symbols after the real value, returning False in such case. Reading of real-valued attributes (single real, array, list) from OCAF XML format is improved to create valid attribute even if parsing of (some) members fails; warning is generated instead of error in such case. Added test bugs caf bug29452
This commit is contained in:
@@ -23,6 +23,8 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <limits>
|
||||
|
||||
static const char aRefPrefix [] = "/document/label";
|
||||
static const char aRefElem1 [] = "/label[@tag=";
|
||||
static const char aRefElem2 [] = "]";
|
||||
@@ -344,11 +346,37 @@ Standard_Boolean XmlObjMgt::GetReal (Standard_CString& theString,
|
||||
{
|
||||
char * ptr;
|
||||
errno = 0;
|
||||
double aValue = Strtod (theString, &ptr);
|
||||
theValue = Strtod (theString, &ptr);
|
||||
if (ptr == theString || errno == ERANGE || errno == EINVAL)
|
||||
return Standard_False;
|
||||
theValue = Standard_Real (aValue);
|
||||
|
||||
theString = ptr;
|
||||
|
||||
// detect NAN or infinite values written by old MSVC run-time as -1. with
|
||||
// suffix "#QNAN" or "#SNAN" or "#INF"
|
||||
if (*ptr == '#')
|
||||
{
|
||||
if (! strncmp (ptr, "#QNAN", 5) || ! strncmp (ptr, "#SNAN", 5))
|
||||
{
|
||||
theString = ptr + 5;
|
||||
theValue = std::numeric_limits<double>::quiet_NaN();
|
||||
return Standard_True;
|
||||
}
|
||||
else if (! strncmp (ptr, "#INF", 4))
|
||||
{
|
||||
theString = ptr + 4;
|
||||
theValue = (theValue < 0 ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity());
|
||||
return Standard_True;
|
||||
}
|
||||
else
|
||||
return Standard_False;
|
||||
}
|
||||
else if (*ptr && ! IsSpace (*ptr))
|
||||
{
|
||||
// report failure if reading stopped not at the end of the string or space
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
@@ -371,13 +399,8 @@ Standard_Boolean XmlObjMgt::GetReal (const XmlObjMgt_DOMString& theString,
|
||||
}
|
||||
default: // LDOM_Ascii*
|
||||
{
|
||||
char * ptr;
|
||||
const char * aString = theString.GetString();
|
||||
errno = 0;
|
||||
double aValue = Strtod (aString, &ptr);
|
||||
if (ptr == aString || errno == ERANGE || errno == EINVAL)
|
||||
return Standard_False;
|
||||
theValue = Standard_Real (aValue);
|
||||
return GetReal (aString, theValue);
|
||||
}
|
||||
}
|
||||
return Standard_True;
|
||||
|
Reference in New Issue
Block a user