329 lines
9.8 KiB
Diff
329 lines
9.8 KiB
Diff
From 9bd7abfba41ca219ab39cb912f020f8e02116f32 Mon Sep 17 00:00:00 2001
|
|
From: Nick Wellnhofer <wellnhofer@aevum.de>
|
|
Date: Thu, 2 Jan 2020 14:14:48 +0100
|
|
Subject: [PATCH] Remove useless comparisons
|
|
|
|
Found by lgtm.com
|
|
---
|
|
nanoftp.c | 3 +-
|
|
parser.c | 1 -
|
|
valid.c | 43 ++++++------
|
|
xmlregexp.c | 4 +-
|
|
xmlschemas.c | 191 +++++++++++++++++++++++++--------------------------
|
|
5 files changed, 117 insertions(+), 125 deletions(-)
|
|
|
|
diff --git a/nanoftp.c b/nanoftp.c
|
|
index 54fa026d..80685da4 100644
|
|
--- a/nanoftp.c
|
|
+++ b/nanoftp.c
|
|
@@ -1251,8 +1251,7 @@ xmlNanoFTPConnectTo(const char *server, int port) {
|
|
xmlNanoFTPFreeCtxt(ctxt);
|
|
return(NULL);
|
|
}
|
|
- if (port != 0)
|
|
- ctxt->port = port;
|
|
+ ctxt->port = port;
|
|
res = xmlNanoFTPConnect(ctxt);
|
|
if (res < 0) {
|
|
xmlNanoFTPFreeCtxt(ctxt);
|
|
diff --git a/parser.c b/parser.c
|
|
index a34bb6cd..43a1a0ab 100644
|
|
--- a/parser.c
|
|
+++ b/parser.c
|
|
@@ -3912,7 +3912,6 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
|
|
"AttValue length too long\n");
|
|
goto mem_error;
|
|
}
|
|
- if (c == 0) break;
|
|
if (c == '&') {
|
|
in_space = 0;
|
|
if (NXT(1) == '#') {
|
|
diff --git a/valid.c b/valid.c
|
|
index 07963e74..b828bc65 100644
|
|
--- a/valid.c
|
|
+++ b/valid.c
|
|
@@ -5919,28 +5919,27 @@ xmlValidatePushCData(xmlValidCtxtPtr ctxt, const xmlChar *data, int len) {
|
|
break;
|
|
case XML_ELEMENT_TYPE_MIXED:
|
|
break;
|
|
- case XML_ELEMENT_TYPE_ELEMENT:
|
|
- if (len > 0) {
|
|
- int i;
|
|
-
|
|
- for (i = 0;i < len;i++) {
|
|
- if (!IS_BLANK_CH(data[i])) {
|
|
- xmlErrValidNode(ctxt, state->node,
|
|
- XML_DTD_CONTENT_MODEL,
|
|
- "Element %s content does not follow the DTD, Text not allowed\n",
|
|
- state->node->name, NULL, NULL);
|
|
- ret = 0;
|
|
- goto done;
|
|
- }
|
|
- }
|
|
- /*
|
|
- * TODO:
|
|
- * VC: Standalone Document Declaration
|
|
- * element types with element content, if white space
|
|
- * occurs directly within any instance of those types.
|
|
- */
|
|
- }
|
|
- break;
|
|
+ case XML_ELEMENT_TYPE_ELEMENT: {
|
|
+ int i;
|
|
+
|
|
+ for (i = 0;i < len;i++) {
|
|
+ if (!IS_BLANK_CH(data[i])) {
|
|
+ xmlErrValidNode(ctxt, state->node,
|
|
+ XML_DTD_CONTENT_MODEL,
|
|
+ "Element %s content does not follow the DTD, Text not allowed\n",
|
|
+ state->node->name, NULL, NULL);
|
|
+ ret = 0;
|
|
+ goto done;
|
|
+ }
|
|
+ }
|
|
+ /*
|
|
+ * TODO:
|
|
+ * VC: Standalone Document Declaration
|
|
+ * element types with element content, if white space
|
|
+ * occurs directly within any instance of those types.
|
|
+ */
|
|
+ break;
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
diff --git a/xmlregexp.c b/xmlregexp.c
|
|
index c119ff1f..5a2deb9e 100644
|
|
--- a/xmlregexp.c
|
|
+++ b/xmlregexp.c
|
|
@@ -6055,7 +6055,7 @@ xmlAutomataNewOnceTrans2(xmlAutomataPtr am, xmlAutomataStatePtr from,
|
|
return(NULL);
|
|
if (min < 1)
|
|
return(NULL);
|
|
- if ((max < min) || (max < 1))
|
|
+ if (max < min)
|
|
return(NULL);
|
|
atom = xmlRegNewAtom(am, XML_REGEXP_STRING);
|
|
if (atom == NULL)
|
|
@@ -6134,7 +6134,7 @@ xmlAutomataNewOnceTrans(xmlAutomataPtr am, xmlAutomataStatePtr from,
|
|
return(NULL);
|
|
if (min < 1)
|
|
return(NULL);
|
|
- if ((max < min) || (max < 1))
|
|
+ if (max < min)
|
|
return(NULL);
|
|
atom = xmlRegNewAtom(am, XML_REGEXP_STRING);
|
|
if (atom == NULL)
|
|
diff --git a/xmlschemas.c b/xmlschemas.c
|
|
index d19de6df..301c8449 100644
|
|
--- a/xmlschemas.c
|
|
+++ b/xmlschemas.c
|
|
@@ -24184,7 +24184,7 @@ xmlSchemaValidateFacets(xmlSchemaAbstractCtxtPtr actxt,
|
|
unsigned long length,
|
|
int fireErrors)
|
|
{
|
|
- int ret, error = 0;
|
|
+ int ret, error = 0, found;
|
|
|
|
xmlSchemaTypePtr tmpType;
|
|
xmlSchemaFacetLinkPtr facetLink;
|
|
@@ -24308,103 +24308,98 @@ WXS_IS_LIST:
|
|
}
|
|
|
|
pattern_and_enum:
|
|
- if (error >= 0) {
|
|
- int found = 0;
|
|
- /*
|
|
- * Process enumerations. Facet values are in the value space
|
|
- * of the defining type's base type. This seems to be a bug in the
|
|
- * XML Schema 1.0 spec. Use the whitespace type of the base type.
|
|
- * Only the first set of enumerations in the ancestor-or-self axis
|
|
- * is used for validation.
|
|
- */
|
|
- ret = 0;
|
|
- tmpType = type;
|
|
- do {
|
|
- for (facet = tmpType->facets; facet != NULL; facet = facet->next) {
|
|
- if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
|
|
- continue;
|
|
- found = 1;
|
|
- ret = xmlSchemaAreValuesEqual(facet->val, val);
|
|
- if (ret == 1)
|
|
- break;
|
|
- else if (ret < 0) {
|
|
- AERROR_INT("xmlSchemaValidateFacets",
|
|
- "validating against an enumeration facet");
|
|
- return (-1);
|
|
- }
|
|
- }
|
|
- if (ret != 0)
|
|
- break;
|
|
- /*
|
|
- * Break on the first set of enumerations. Any additional
|
|
- * enumerations which might be existent on the ancestors
|
|
- * of the current type are restricted by this set; thus
|
|
- * *must* *not* be taken into account.
|
|
- */
|
|
- if (found)
|
|
- break;
|
|
- tmpType = tmpType->baseType;
|
|
- } while ((tmpType != NULL) &&
|
|
- (tmpType->type != XML_SCHEMA_TYPE_BASIC));
|
|
- if (found && (ret == 0)) {
|
|
- ret = XML_SCHEMAV_CVC_ENUMERATION_VALID;
|
|
- if (fireErrors) {
|
|
- xmlSchemaFacetErr(actxt, ret, node,
|
|
- value, 0, type, NULL, NULL, NULL, NULL);
|
|
- } else
|
|
- return (ret);
|
|
- if (error == 0)
|
|
- error = ret;
|
|
- }
|
|
- }
|
|
-
|
|
- if (error >= 0) {
|
|
- int found;
|
|
- /*
|
|
- * Process patters. Pattern facets are ORed at type level
|
|
- * and ANDed if derived. Walk the base type axis.
|
|
- */
|
|
- tmpType = type;
|
|
- facet = NULL;
|
|
- do {
|
|
- found = 0;
|
|
- for (facetLink = tmpType->facetSet; facetLink != NULL;
|
|
- facetLink = facetLink->next) {
|
|
- if (facetLink->facet->type != XML_SCHEMA_FACET_PATTERN)
|
|
- continue;
|
|
- found = 1;
|
|
- /*
|
|
- * NOTE that for patterns, @value needs to be the
|
|
- * normalized value.
|
|
- */
|
|
- ret = xmlRegexpExec(facetLink->facet->regexp, value);
|
|
- if (ret == 1)
|
|
- break;
|
|
- else if (ret < 0) {
|
|
- AERROR_INT("xmlSchemaValidateFacets",
|
|
- "validating against a pattern facet");
|
|
- return (-1);
|
|
- } else {
|
|
- /*
|
|
- * Save the last non-validating facet.
|
|
- */
|
|
- facet = facetLink->facet;
|
|
- }
|
|
- }
|
|
- if (found && (ret != 1)) {
|
|
- ret = XML_SCHEMAV_CVC_PATTERN_VALID;
|
|
- if (fireErrors) {
|
|
- xmlSchemaFacetErr(actxt, ret, node,
|
|
- value, 0, type, facet, NULL, NULL, NULL);
|
|
- } else
|
|
- return (ret);
|
|
- if (error == 0)
|
|
- error = ret;
|
|
- break;
|
|
- }
|
|
- tmpType = tmpType->baseType;
|
|
- } while ((tmpType != NULL) && (tmpType->type != XML_SCHEMA_TYPE_BASIC));
|
|
- }
|
|
+ found = 0;
|
|
+ /*
|
|
+ * Process enumerations. Facet values are in the value space
|
|
+ * of the defining type's base type. This seems to be a bug in the
|
|
+ * XML Schema 1.0 spec. Use the whitespace type of the base type.
|
|
+ * Only the first set of enumerations in the ancestor-or-self axis
|
|
+ * is used for validation.
|
|
+ */
|
|
+ ret = 0;
|
|
+ tmpType = type;
|
|
+ do {
|
|
+ for (facet = tmpType->facets; facet != NULL; facet = facet->next) {
|
|
+ if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
|
|
+ continue;
|
|
+ found = 1;
|
|
+ ret = xmlSchemaAreValuesEqual(facet->val, val);
|
|
+ if (ret == 1)
|
|
+ break;
|
|
+ else if (ret < 0) {
|
|
+ AERROR_INT("xmlSchemaValidateFacets",
|
|
+ "validating against an enumeration facet");
|
|
+ return (-1);
|
|
+ }
|
|
+ }
|
|
+ if (ret != 0)
|
|
+ break;
|
|
+ /*
|
|
+ * Break on the first set of enumerations. Any additional
|
|
+ * enumerations which might be existent on the ancestors
|
|
+ * of the current type are restricted by this set; thus
|
|
+ * *must* *not* be taken into account.
|
|
+ */
|
|
+ if (found)
|
|
+ break;
|
|
+ tmpType = tmpType->baseType;
|
|
+ } while ((tmpType != NULL) &&
|
|
+ (tmpType->type != XML_SCHEMA_TYPE_BASIC));
|
|
+ if (found && (ret == 0)) {
|
|
+ ret = XML_SCHEMAV_CVC_ENUMERATION_VALID;
|
|
+ if (fireErrors) {
|
|
+ xmlSchemaFacetErr(actxt, ret, node,
|
|
+ value, 0, type, NULL, NULL, NULL, NULL);
|
|
+ } else
|
|
+ return (ret);
|
|
+ if (error == 0)
|
|
+ error = ret;
|
|
+ }
|
|
+
|
|
+ /*
|
|
+ * Process patters. Pattern facets are ORed at type level
|
|
+ * and ANDed if derived. Walk the base type axis.
|
|
+ */
|
|
+ tmpType = type;
|
|
+ facet = NULL;
|
|
+ do {
|
|
+ found = 0;
|
|
+ for (facetLink = tmpType->facetSet; facetLink != NULL;
|
|
+ facetLink = facetLink->next) {
|
|
+ if (facetLink->facet->type != XML_SCHEMA_FACET_PATTERN)
|
|
+ continue;
|
|
+ found = 1;
|
|
+ /*
|
|
+ * NOTE that for patterns, @value needs to be the
|
|
+ * normalized value.
|
|
+ */
|
|
+ ret = xmlRegexpExec(facetLink->facet->regexp, value);
|
|
+ if (ret == 1)
|
|
+ break;
|
|
+ else if (ret < 0) {
|
|
+ AERROR_INT("xmlSchemaValidateFacets",
|
|
+ "validating against a pattern facet");
|
|
+ return (-1);
|
|
+ } else {
|
|
+ /*
|
|
+ * Save the last non-validating facet.
|
|
+ */
|
|
+ facet = facetLink->facet;
|
|
+ }
|
|
+ }
|
|
+ if (found && (ret != 1)) {
|
|
+ ret = XML_SCHEMAV_CVC_PATTERN_VALID;
|
|
+ if (fireErrors) {
|
|
+ xmlSchemaFacetErr(actxt, ret, node,
|
|
+ value, 0, type, facet, NULL, NULL, NULL);
|
|
+ } else
|
|
+ return (ret);
|
|
+ if (error == 0)
|
|
+ error = ret;
|
|
+ break;
|
|
+ }
|
|
+ tmpType = tmpType->baseType;
|
|
+ } while ((tmpType != NULL) && (tmpType->type != XML_SCHEMA_TYPE_BASIC));
|
|
|
|
return (error);
|
|
}
|
|
--
|
|
2.27.0
|
|
|