fixed bugs and memory leaks in the W3C XML Schemas code implemented
* xmlschemas.c include/libxml/xmlschemas.h: fixed bugs and memory
leaks in the W3C XML Schemas code
* xmlschemastypes.c: implemented nonPositiveInteger
* test/schemas/length2_0.xsd result/schemas/length2_0_0.err:
fixed the test and result.
Daniel
diff --git a/ChangeLog b/ChangeLog
index 79ded7e..e64e9d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Fri Mar 28 00:41:55 CET 2003 Daniel Veillard <daniel@veillard.com>
+
+ * xmlschemas.c include/libxml/xmlschemas.h: fixed bugs and memory
+ leaks in the W3C XML Schemas code
+ * xmlschemastypes.c: implemented nonPositiveInteger
+ * test/schemas/length2_0.xsd result/schemas/length2_0_0.err:
+ fixed the test and result.
+
Thu Mar 27 22:23:07 CET 2003 Daniel Veillard <daniel@veillard.com>
* HTMLparser.c tree.c: two patches from James Bursa on the HTML
diff --git a/include/libxml/xmlschemas.h b/include/libxml/xmlschemas.h
index 14b9230..081d8a2 100644
--- a/include/libxml/xmlschemas.h
+++ b/include/libxml/xmlschemas.h
@@ -44,6 +44,7 @@
XML_SCHEMAS_ERR_NOTSIMPLE,
XML_SCHEMAS_ERR_ATTRUNKNOWN,
XML_SCHEMAS_ERR_ATTRINVALID,
+ XML_SCHEMAS_ERR_VALUE,
XML_SCHEMAS_ERR_,
XML_SCHEMAS_ERR_XXX
} xmlSchemaValidError;
diff --git a/result/schemas/length2_0_0.err b/result/schemas/length2_0_0.err
index dd19dab..22aa61e 100644
--- a/result/schemas/length2_0_0.err
+++ b/result/schemas/length2_0_0.err
@@ -1,4 +1,3 @@
-Unable to lookup type nonPositiveInteger:http://www.w3.org/2001/XMLSchemaSchemas: element size type nonPositiveInteger not found
Type of sequence 3 : ./test/schemas/length2_0.xsd:6 :elements
Type of restriction 2 : ./test/schemas/length2_0.xsd:5 :elements
Type of complexContent 1 : ./test/schemas/length2_0.xsd:4 :elements
diff --git a/test/schemas/length2_0.xsd b/test/schemas/length2_0.xsd
index 4344a70..76d73c0 100644
--- a/test/schemas/length2_0.xsd
+++ b/test/schemas/length2_0.xsd
@@ -4,7 +4,7 @@
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:sequence>
- <xs:element name="size" type="xs:nonPositiveInteger"/>
+ <xs:element name="size" type="xs:nonNegativeInteger"/>
<xs:element name="unit" type="xs:NMTOKEN"/>
</xs:sequence>
</xs:restriction>
diff --git a/xmlschemas.c b/xmlschemas.c
index bc6f4d3..6c9e2f4 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -278,6 +278,10 @@
return;
if (attr->name != NULL)
xmlFree((xmlChar *) attr->name);
+ if (attr->ref != NULL)
+ xmlFree((xmlChar *) attr->ref);
+ if (attr->refNs != NULL)
+ xmlFree((xmlChar *) attr->refNs);
xmlFree(attr);
}
@@ -377,6 +381,10 @@
if (schema == NULL)
return;
+ if (schema->id != NULL)
+ xmlFree((xmlChar *) schema->id);
+ if (schema->targetNamespace != NULL)
+ xmlFree((xmlChar *) schema->targetNamespace);
if (schema->name != NULL)
xmlFree((xmlChar *) schema->name);
if (schema->notaDecl != NULL)
@@ -1661,6 +1669,12 @@
}
snprintf(buf, 99, "anonattrgroup%d", ctxt->counter++ + 1);
name = xmlStrdup((xmlChar *) buf);
+ if (name == NULL) {
+ if ((ctxt != NULL) && (ctxt->error != NULL))
+ ctxt->error(ctxt->userData,
+ "out of memory\n");
+ return (NULL);
+ }
}
ret = xmlSchemaAddAttributeGroup(ctxt, schema, name);
if (ret == NULL) {
@@ -1711,6 +1725,7 @@
}
ctxt->container = oldcontainer;
+ xmlFree(name);
return (ret);
}
@@ -4841,6 +4856,7 @@
ctxt->error(ctxt->userData,
"Element %s: failed to validate basic type %s\n",
node->name, type->name);
+ ctxt->err = XML_SCHEMAS_ERR_VALUE;
}
return(ret);
}
diff --git a/xmlschemastypes.c b/xmlschemastypes.c
index fa13502..1ef762f 100644
--- a/xmlschemastypes.c
+++ b/xmlschemastypes.c
@@ -1286,8 +1286,7 @@
if (*cur == '-') {
sign = 1;
cur++;
- } else if (*cur == '+')
- cur++;
+ }
while ((*cur >= '0') && (*cur <= '9')) {
base = base * 10 + (*cur - '0');
total++;
@@ -1308,6 +1307,37 @@
}
}
return(0);
+ } else if (type == xmlSchemaTypeNonPositiveIntegerDef) {
+ const xmlChar *cur = value;
+ unsigned long base = 0;
+ int total = 0;
+ int sign = 0;
+ if (cur == NULL)
+ return(1);
+ if (*cur == '-') {
+ sign = 1;
+ cur++;
+ }
+ while ((*cur >= '0') && (*cur <= '9')) {
+ base = base * 10 + (*cur - '0');
+ total++;
+ cur++;
+ }
+ if (*cur != 0)
+ return(1);
+ if ((sign != 1) && (base != 0))
+ return(1);
+ if (val != NULL) {
+ v = xmlSchemaNewValue(XML_SCHEMAS_DECIMAL);
+ if (v != NULL) {
+ v->value.decimal.base = base;
+ v->value.decimal.sign = 0;
+ v->value.decimal.frac = 0;
+ v->value.decimal.total = total;
+ *val = v;
+ }
+ }
+ return(0);
} else if (type == xmlSchemaTypeIntDef) {
const xmlChar *cur = value;
unsigned long base = 0;