You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by db...@apache.org on 2005/06/08 20:41:07 UTC
svn commit: r189619 - in /xerces/c/trunk/src/xercesc:
framework/psvi/XSValue.cpp util/XMLAbstractDoubleFloat.cpp
util/XMLAbstractDoubleFloat.hpp util/XMLDouble.cpp util/XMLDouble.hpp
util/XMLFloat.cpp util/XMLFloat.hpp
Author: dbertoni
Date: Wed Jun 8 11:41:06 2005
New Revision: 189619
URL: http://svn.apache.org/viewcvs?rev=189619&view=rev
Log:
Fixes for Jira issue XERCESC-1409.
Modified:
xerces/c/trunk/src/xercesc/framework/psvi/XSValue.cpp
xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.cpp
xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.hpp
xerces/c/trunk/src/xercesc/util/XMLDouble.cpp
xerces/c/trunk/src/xercesc/util/XMLDouble.hpp
xerces/c/trunk/src/xercesc/util/XMLFloat.cpp
xerces/c/trunk/src/xercesc/util/XMLFloat.hpp
Modified: xerces/c/trunk/src/xercesc/framework/psvi/XSValue.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/framework/psvi/XSValue.cpp?rev=189619&r1=189618&r2=189619&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/framework/psvi/XSValue.cpp (original)
+++ xerces/c/trunk/src/xercesc/framework/psvi/XSValue.cpp Wed Jun 8 11:41:06 2005
@@ -1788,15 +1788,23 @@
status = st_FOCA0003;
return false;
}
- // check if all chars are valid char
- if ( (endptr - nptr) != strLen)
+ // check if all chars are valid char. If they are, endptr will
+ // pointer to the null terminator, or all of the remaining
+ // characters will be whitespace characters.
+ while (*endptr != '\0')
{
- for (unsigned int i=endptr - nptr; i <strLen; i++) {
- if (!isspace(nptr[i])) {
- status = st_FOCA0002;
- return false;
- }
+ const char ch = *endptr;
+
+ if (ch == '\t' || ch == '\n' || ch == '\r' || ch == ' ')
+ {
+ ++endptr;
}
+ else
+ {
+ status = st_FOCA0002;
+ return false;
+ }
+
}
return true;
}
Modified: xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.cpp?rev=189619&r1=189618&r2=189619&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.cpp Wed Jun 8 11:41:06 2005
@@ -132,6 +132,8 @@
#include <xercesc/util/Janitor.hpp>
#include <locale.h>
+#include <float.h>
+#include <errno.h>
XERCES_CPP_NAMESPACE_BEGIN
@@ -199,7 +201,55 @@
// Normal case
//
{
- checkBoundary(tmpStrValue);
+ // Use a stack-based buffer when possible. Since all
+ // valid doubles or floats will only contain ASCII
+ // digits, a decimal point, or the exponent character,
+ // they will all be single byte characters, and this will
+ // work.
+ static const unsigned int maxStackSize = 100;
+
+ const unsigned int lenTempStrValue =
+ XMLString::stringLen(tmpStrValue);
+
+ if (lenTempStrValue < maxStackSize)
+ {
+ char buffer[maxStackSize + 1];
+
+ XMLString::transcode(
+ tmpStrValue,
+ buffer,
+ sizeof(buffer) - 1,
+ getMemoryManager());
+
+ // Do this for safety, because we've
+ // no guarantee we didn't overrun the
+ // capacity of the buffer when transcoding
+ // a bogus value.
+ buffer[maxStackSize] = '\0';
+
+ // If they aren't the same length, then some
+ // non-ASCII multibyte character was present.
+ // This will only happen in the case where the
+ // string has a bogus character, and it's long
+ // enough to overrun this buffer, but we need
+ // to check, even if it's unlikely to happen.
+ if (XMLString::stringLen(buffer) != lenTempStrValue)
+ {
+ ThrowXMLwithMemMgr(
+ NumberFormatException,
+ XMLExcepts::XMLNUM_Inv_chars,
+ getMemoryManager());
+ }
+
+ checkBoundary(buffer);
+ }
+ else
+ {
+ char *nptr = XMLString::transcode(tmpStrValue, getMemoryManager());
+ const ArrayJanitor<char> janStr(nptr, fMemoryManager);
+
+ checkBoundary(nptr);
+ }
}
}
@@ -465,6 +515,58 @@
}
}
}
+
+
+void
+XMLAbstractDoubleFloat::convert(char* const strValue)
+{
+ normalizeDecimalPoint(strValue);
+
+ char *endptr = 0;
+ errno = 0;
+ fValue = strtod(strValue, &endptr);
+
+ // check if all chars are valid char. If they are, endptr will
+ // pointer to the null terminator.
+ if (*endptr != '\0')
+ {
+ ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_Inv_chars, getMemoryManager());
+ }
+
+ // check if overflow/underflow occurs
+ if (errno == ERANGE)
+ {
+
+ fDataConverted = true;
+
+ if ( fValue < 0 )
+ {
+ if (fValue > (-1)*DBL_MIN)
+ {
+ fValue = 0;
+ }
+ else
+ {
+ fType = NegINF;
+ fDataOverflowed = true;
+ }
+ }
+ else if ( fValue > 0)
+ {
+ if (fValue < DBL_MIN )
+ {
+ fValue = 0;
+ }
+ else
+ {
+ fType = PosINF;
+ fDataOverflowed = true;
+ }
+ }
+ }
+}
+
+
/***
* E2-40
Modified: xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.hpp?rev=189619&r1=189618&r2=189619&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.hpp Wed Jun 8 11:41:06 2005
@@ -195,7 +195,7 @@
* from string to double/float.
*
***/
- void normalizeDecimalPoint(char* const toNormal);
+ static void normalizeDecimalPoint(char* const toNormal);
/***
* Support for Serialization/De-serialization
@@ -229,9 +229,12 @@
, MemoryManager* const manager);
//
- // to be overwritten by derived class
+ // to be overridden by derived class
//
- virtual void checkBoundary(const XMLCh* const strValue) = 0;
+ virtual void checkBoundary(char* const strValue) = 0;
+
+ void
+ convert(char* const strValue);
private:
//
Modified: xerces/c/trunk/src/xercesc/util/XMLDouble.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/XMLDouble.cpp?rev=189619&r1=189618&r2=189619&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLDouble.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLDouble.cpp Wed Jun 8 11:41:06 2005
@@ -122,8 +122,6 @@
#include <string.h>
#include <stdlib.h>
-#include <errno.h>
-#include <float.h>
XERCES_CPP_NAMESPACE_BEGIN
@@ -141,57 +139,9 @@
{
}
-void XMLDouble::checkBoundary(const XMLCh* const strValue)
+void XMLDouble::checkBoundary(char* const strValue)
{
- char *nptr = XMLString::transcode(strValue, getMemoryManager());
-
- normalizeDecimalPoint(nptr);
-
- ArrayJanitor<char> jan1(nptr, getMemoryManager());
- int strLen = strlen(nptr);
- char *endptr = 0;
- errno = 0;
- fValue = strtod(nptr, &endptr);
-
- // check if all chars are valid char
- if ( (endptr - nptr) != strLen)
- {
- ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_Inv_chars, getMemoryManager());
- }
-
- // check if overflow/underflow occurs
- if (errno == ERANGE)
- {
-
- fDataConverted = true;
-
- if ( fValue < 0 )
- {
- if (fValue > (-1)*DBL_MIN)
- {
- fValue = 0;
- }
- else
- {
- fType = NegINF;
- fDataOverflowed = true;
- }
- }
- else if ( fValue > 0)
- {
- if (fValue < DBL_MIN )
- {
- fValue = 0;
- }
- else
- {
- fType = PosINF;
- fDataOverflowed = true;
- }
- }
-
- }
-
+ convert(strValue);
}
/***
Modified: xerces/c/trunk/src/xercesc/util/XMLDouble.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/XMLDouble.hpp?rev=189619&r1=189618&r2=189619&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLDouble.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLDouble.hpp Wed Jun 8 11:41:06 2005
@@ -128,7 +128,7 @@
protected:
- void checkBoundary(const XMLCh* const strValue);
+ virtual void checkBoundary(char* const strValue);
private:
//
Modified: xerces/c/trunk/src/xercesc/util/XMLFloat.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/XMLFloat.cpp?rev=189619&r1=189618&r2=189619&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLFloat.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLFloat.cpp Wed Jun 8 11:41:06 2005
@@ -136,56 +136,11 @@
{
}
-void XMLFloat::checkBoundary(const XMLCh* const strValue)
+void XMLFloat::checkBoundary(char* const strValue)
{
- char *nptr = XMLString::transcode(strValue, getMemoryManager());
+ convert(strValue);
- normalizeDecimalPoint(nptr);
-
- ArrayJanitor<char> jan1(nptr, getMemoryManager());
- int strLen = strlen(nptr);
- char *endptr = 0;
- errno = 0;
- fValue = strtod(nptr, &endptr);
-
- // check if all chars are valid char
- if ( (endptr - nptr) != strLen)
- {
- ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_Inv_chars, getMemoryManager());
- }
-
- // check if overflow/underflow occurs
- if (errno == ERANGE)
- {
-
- fDataConverted = true;
-
- if ( fValue < 0 )
- {
- if (fValue > (-1)*DBL_MIN)
- {
- fValue = 0;
- }
- else
- {
- fType = NegINF;
- fDataOverflowed = true;
- }
- }
- else if ( fValue > 0)
- {
- if (fValue < DBL_MIN )
- {
- fValue = 0;
- }
- else
- {
- fType = PosINF;
- fDataOverflowed = true;
- }
- }
- }
- else
+ if (fDataConverted == false)
{
/**
* float related checking
Modified: xerces/c/trunk/src/xercesc/util/XMLFloat.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/XMLFloat.hpp?rev=189619&r1=189618&r2=189619&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLFloat.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLFloat.hpp Wed Jun 8 11:41:06 2005
@@ -122,7 +122,7 @@
protected:
- void checkBoundary(const XMLCh* const strValue);
+ virtual void checkBoundary(char* const strValue);
private:
//
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org