NPOTDB Usage of INF -INF with float and double not as expected. Bug 338005, patch by sspeiche, r=doronr

This commit is contained in:
aaronr%us.ibm.com 2006-05-24 06:44:21 +00:00
Родитель 2fa6242e31
Коммит 8f7e65ed98
3 изменённых файлов: 115 добавлений и 53 удалений

Просмотреть файл

@ -71,6 +71,7 @@
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include "prprf.h"
#include "prtime.h"
#include "plbase64.h"
@ -2818,42 +2819,70 @@ nsSchemaValidator::ValidateBuiltinTypeFloat(const nsAString & aNodeValue,
isValid = IsValidSchemaFloat(aNodeValue, &floatValue);
if (isValid && !aMaxExclusive.IsEmpty()){
float maxExclusive;
if (IsValidSchemaFloat(aMaxExclusive, &maxExclusive) &&
(floatValue >= maxExclusive)) {
// If there is a facet and value is NaN,
// then it is not valid.
if (aNodeValue.EqualsLiteral("NaN")) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too big", floatValue));
LOG((" Not valid: Value NaN can't be constrained by facets"));
} else {
float maxExclusive;
if (IsValidSchemaFloat(aMaxExclusive, &maxExclusive) &&
(floatValue >= maxExclusive)) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too big", floatValue));
}
}
}
if (isValid && !aMinExclusive.IsEmpty()){
float minExclusive;
if (IsValidSchemaFloat(aMinExclusive, &minExclusive) &&
(floatValue <= minExclusive)) {
// If there is a facet and value is NaN,
// then it is not valid.
if (aNodeValue.EqualsLiteral("NaN")) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too small", floatValue));
LOG((" Not valid: Value NaN can't be constrained by facets"));
} else {
float minExclusive;
if (IsValidSchemaFloat(aMinExclusive, &minExclusive) &&
(floatValue <= minExclusive)) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too small", floatValue));
}
}
}
if (isValid && !aMaxInclusive.IsEmpty()){
float maxInclusive;
if (IsValidSchemaFloat(aMaxInclusive, &maxInclusive) &&
(floatValue > maxInclusive)) {
// If there is a facet and value is NaN,
// then it is not valid.
if (aNodeValue.EqualsLiteral("NaN")) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too big", floatValue));
LOG((" Not valid: Value NaN can't be constrained by facets"));
} else {
float maxInclusive;
if (IsValidSchemaFloat(aMaxInclusive, &maxInclusive) &&
(floatValue > maxInclusive)) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too big", floatValue));
}
}
}
if (isValid && !aMinInclusive.IsEmpty()){
float minInclusive;
if (IsValidSchemaFloat(aMinInclusive, &minInclusive) &&
(floatValue < minInclusive)) {
// If there is a facet and value is NaN,
// then it is not valid.
if (aNodeValue.EqualsLiteral("NaN")) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too small", floatValue));
LOG((" Not valid: Value NaN can't be constrained by facets"));
} else {
float minInclusive;
if (IsValidSchemaFloat(aMinInclusive, &minInclusive) &&
(floatValue < minInclusive)) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too small", floatValue));
}
}
}
@ -2881,8 +2910,11 @@ nsSchemaValidator::IsValidSchemaFloat(const nsAString & aNodeValue,
float floatValue = temp.ToFloat(&errorCode);
if (NS_FAILED(errorCode)) {
// floats may be INF, -INF and NaN
if (!aNodeValue.EqualsLiteral("INF") && !aNodeValue.EqualsLiteral("-INF") &&
!aNodeValue.EqualsLiteral("NaN")) {
if (aNodeValue.EqualsLiteral("INF")) {
floatValue = FLT_MAX;
} else if (aNodeValue.EqualsLiteral("-INF")) {
floatValue = - FLT_MAX;
} else if (!aNodeValue.EqualsLiteral("NaN")) {
isValid = PR_FALSE;
}
}
@ -2910,42 +2942,70 @@ nsSchemaValidator::ValidateBuiltinTypeDouble(const nsAString & aNodeValue,
isValid = IsValidSchemaDouble(aNodeValue, &doubleValue);
if (isValid && !aMaxExclusive.IsEmpty()) {
double maxExclusive;
if (IsValidSchemaDouble(aMaxExclusive, &maxExclusive) &&
(doubleValue >= maxExclusive)) {
// If there is a facet and value is NaN,
// then it is not valid.
if (aNodeValue.EqualsLiteral("NaN")) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too big", doubleValue));
LOG((" Not valid: Value NaN can't be constrained by facets"));
} else {
double maxExclusive;
if (IsValidSchemaDouble(aMaxExclusive, &maxExclusive) &&
(doubleValue >= maxExclusive)) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too big", doubleValue));
}
}
}
if (isValid && !aMinExclusive.IsEmpty()) {
double minExclusive;
if (IsValidSchemaDouble(aMinExclusive, &minExclusive) &&
(doubleValue <= minExclusive)) {
// If there is a facet and value is NaN,
// then it is not valid.
if (aNodeValue.EqualsLiteral("NaN")) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too small", doubleValue));
LOG((" Not valid: Value NaN can't be constrained by facets"));
} else {
double minExclusive;
if (IsValidSchemaDouble(aMinExclusive, &minExclusive) &&
(doubleValue <= minExclusive)) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too small", doubleValue));
}
}
}
if (isValid && !aMaxInclusive.IsEmpty()) {
double maxInclusive;
if (IsValidSchemaDouble(aMaxInclusive, &maxInclusive) &&
(doubleValue > maxInclusive)) {
// If there is a facet and value is NaN,
// then it is not valid.
if (aNodeValue.EqualsLiteral("NaN")) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too big", doubleValue));
LOG((" Not valid: Value NaN can't be constrained by facets"));
} else {
double maxInclusive;
if (IsValidSchemaDouble(aMaxInclusive, &maxInclusive) &&
(doubleValue > maxInclusive)) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too big", doubleValue));
}
}
}
if (isValid && !aMinInclusive.IsEmpty()) {
double minInclusive;
if (IsValidSchemaDouble(aMinInclusive, &minInclusive) &&
(doubleValue < minInclusive)) {
// If there is a facet and value is NaN,
// then it is not valid.
if (aNodeValue.EqualsLiteral("NaN")) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too small", doubleValue));
LOG((" Not valid: Value NaN can't be constrained by facets"));
} else {
double minInclusive;
if (IsValidSchemaDouble(aMinInclusive, &minInclusive) &&
(doubleValue < minInclusive)) {
isValid = PR_FALSE;
LOG((" Not valid: Value (%f) is too small", doubleValue));
}
}
}

Просмотреть файл

@ -52,6 +52,7 @@
#include <math.h>
#include <errno.h>
#include <limits.h>
#include <float.h>
#include "prlog.h"
#include "prprf.h"
#include "prdtoa.h"
@ -122,21 +123,23 @@ nsSchemaValidatorUtils::IsValidSchemaDouble(const char* aString,
char * pEnd;
double value = PR_strtod(aString, &pEnd);
if (aResult)
*aResult = value;
// If end pointer hasn't moved, then the string wasn't a
// true double (could be INF, -INF or NaN though)
if (pEnd == aString) {
NS_NAMED_LITERAL_CSTRING(temp, aString);
nsCAutoString temp(aString);
// doubles may be INF, -INF or NaN
if (!temp.Equals(NS_LITERAL_CSTRING("INF")) &&
!temp.Equals(NS_LITERAL_CSTRING("-INF")) &&
!temp.Equals(NS_LITERAL_CSTRING("NaN"))) {
if (temp.EqualsLiteral("INF")) {
value = DBL_MAX;
} else if (temp.EqualsLiteral("-INF")) {
value = - DBL_MAX;
} else if (!temp.EqualsLiteral("NaN")) {
isValid = PR_FALSE;
}
}
if (aResult)
*aResult = value;
return isValid;
}

Просмотреть файл

@ -219,11 +219,10 @@
validate("-1.99", "float-test-2", false);
validate("-5.32", "float-test-2", false);
/* XXX Skip boundary tests for now
validate("-INF", "float-test-3", true);
validate("INF", "float-test-3", false);
validate("NaN", "float-test-3", false);
validate("4.21e4", "float-test-3", true); */
validate("4.21e4", "float-test-3", true);
validate("-1", "double-test-1", false);
validate("1.230", "double-test-1", true);
@ -236,7 +235,6 @@
validate("1.230", "double-test-2", true);
validate("1.230E42", "double-test-2", true);
/* XXX Skip boundary tests for now
validate("-INF", "double-test-3", true);
validate("NaN", "double-test-3", true);
@ -244,7 +242,7 @@
validate("INF", "double-test-4", false);
validate("NaN", "double-test-4", false);
validate("1.0E12", "double-test-4", true);
validate("-0", "double-test-4", true); */
validate("-0", "double-test-4", true);
validate("220.343434", "decimal-test-1", true);
validate("220.3434a34", "decimal-test-1", false);
@ -631,6 +629,7 @@
validate("Applicant Trustee Supplier", "IndividualRoleListType5", false);
validate("Applicant Trustee", "IndividualRoleListType5", true);
}
end = new Date();