a lot of small cleanups based on Linus' sparse check output. Daniel

* HTMLparser.c SAX2.c encoding.c globals.c parser.c relaxng.c
  runsuite.c runtest.c schematron.c testHTML.c testReader.c
  testRegexp.c testSAX.c testThreads.c valid.c xinclude.c xmlIO.c
  xmllint.c xmlmodule.c xmlschemas.c xpath.c xpointer.c: a lot of
  small cleanups based on Linus' sparse check output.
Daniel
diff --git a/ChangeLog b/ChangeLog
index 22043aa..727b180 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Fri Jul 29 01:48:02 CEST 2005 Daniel Veillard <daniel@veillard.com>
+
+	* HTMLparser.c SAX2.c encoding.c globals.c parser.c relaxng.c
+	  runsuite.c runtest.c schematron.c testHTML.c testReader.c
+	  testRegexp.c testSAX.c testThreads.c valid.c xinclude.c xmlIO.c
+	  xmllint.c xmlmodule.c xmlschemas.c xpath.c xpointer.c: a lot of 
+	  small cleanups based on Linus' sparse check output.
+
 Thu Jul 28 21:28:33 CEST 2005 Daniel Veillard <daniel@veillard.com>
 
 	* include/libxml/Makefile.am: added schematron.h, oops ...
diff --git a/HTMLparser.c b/HTMLparser.c
index a54fc8d..f4e27aa 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -192,16 +192,16 @@
     const xmlChar *ret;
 
     if (ctxt->nameNr <= 0)
-        return (0);
+        return (NULL);
     ctxt->nameNr--;
     if (ctxt->nameNr < 0)
-        return (0);
+        return (NULL);
     if (ctxt->nameNr > 0)
         ctxt->name = ctxt->nameTab[ctxt->nameNr - 1];
     else
         ctxt->name = NULL;
     ret = ctxt->nameTab[ctxt->nameNr];
-    ctxt->nameTab[ctxt->nameNr] = 0;
+    ctxt->nameTab[ctxt->nameNr] = NULL;
     return (ret);
 }
 
diff --git a/SAX2.c b/SAX2.c
index 16e361f..c8b6244 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -227,7 +227,7 @@
 xmlSAX2GetSystemId(void *ctx)
 {
     xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-    if ((ctx == NULL) || (ctxt->input == NULL)) return(0);
+    if ((ctx == NULL) || (ctxt->input == NULL)) return(NULL);
     return((const xmlChar *) ctxt->input->filename); 
 }
 
diff --git a/encoding.c b/encoding.c
index 66e63b5..3f5d8b4 100644
--- a/encoding.c
+++ b/encoding.c
@@ -1239,7 +1239,7 @@
     const char *alias;
     char upper[500];
     int i;
-    char *up = 0;
+    char *up = NULL;
 
     /*
      * Do the alias resolution
diff --git a/globals.c b/globals.c
index bee542c..fcace75 100644
--- a/globals.c
+++ b/globals.c
@@ -344,7 +344,7 @@
  * Disabled by default
  */
 int xmlSaveNoEmptyTags = 0;
-int xmlSaveNoEmptyTagsThrDef = 0;
+static int xmlSaveNoEmptyTagsThrDef = 0;
 
 #ifdef LIBXML_SAX1_ENABLED
 /**
diff --git a/parser.c b/parser.c
index 13d19a0..e5f3e0c 100644
--- a/parser.c
+++ b/parser.c
@@ -984,14 +984,14 @@
     if (ctxt == NULL)
         return(NULL);
     if (ctxt->inputNr <= 0)
-        return (0);
+        return (NULL);
     ctxt->inputNr--;
     if (ctxt->inputNr > 0)
         ctxt->input = ctxt->inputTab[ctxt->inputNr - 1];
     else
         ctxt->input = NULL;
     ret = ctxt->inputTab[ctxt->inputNr];
-    ctxt->inputTab[ctxt->inputNr] = 0;
+    ctxt->inputTab[ctxt->inputNr] = NULL;
     return (ret);
 }
 /**
@@ -1053,7 +1053,7 @@
     else
         ctxt->node = NULL;
     ret = ctxt->nodeTab[ctxt->nodeNr];
-    ctxt->nodeTab[ctxt->nodeNr] = 0;
+    ctxt->nodeTab[ctxt->nodeNr] = NULL;
     return (ret);
 }
 
@@ -1118,7 +1118,7 @@
     const xmlChar *ret;
 
     if (ctxt->nameNr <= 0)
-        return (0);
+        return (NULL);
     ctxt->nameNr--;
     if (ctxt->nameNr > 0)
         ctxt->name = ctxt->nameTab[ctxt->nameNr - 1];
@@ -1184,7 +1184,7 @@
     else
         ctxt->name = NULL;
     ret = ctxt->nameTab[ctxt->nameNr];
-    ctxt->nameTab[ctxt->nameNr] = 0;
+    ctxt->nameTab[ctxt->nameNr] = NULL;
     return (ret);
 }
 
diff --git a/relaxng.c b/relaxng.c
index 61daa0d..41398e1 100644
--- a/relaxng.c
+++ b/relaxng.c
@@ -1477,14 +1477,14 @@
     xmlRelaxNGIncludePtr ret;
 
     if (ctxt->incNr <= 0)
-        return (0);
+        return (NULL);
     ctxt->incNr--;
     if (ctxt->incNr > 0)
         ctxt->inc = ctxt->incTab[ctxt->incNr - 1];
     else
         ctxt->inc = NULL;
     ret = ctxt->incTab[ctxt->incNr];
-    ctxt->incTab[ctxt->incNr] = 0;
+    ctxt->incTab[ctxt->incNr] = NULL;
     return (ret);
 }
 
@@ -1889,14 +1889,14 @@
     xmlRelaxNGDocumentPtr ret;
 
     if (ctxt->docNr <= 0)
-        return (0);
+        return (NULL);
     ctxt->docNr--;
     if (ctxt->docNr > 0)
         ctxt->doc = ctxt->docTab[ctxt->docNr - 1];
     else
         ctxt->doc = NULL;
     ret = ctxt->docTab[ctxt->docNr];
-    ctxt->docTab[ctxt->docNr] = 0;
+    ctxt->docTab[ctxt->docNr] = NULL;
     return (ret);
 }
 
diff --git a/runsuite.c b/runsuite.c
index b788313..aecd6ae 100644
--- a/runsuite.c
+++ b/runsuite.c
@@ -30,8 +30,8 @@
 #include <libxml/xmlschemastypes.h>
 
 #define LOGFILE "runsuite.log"
-FILE *logfile = NULL;
-int verbose = 0;

+static FILE *logfile = NULL;
+static int verbose = 0;

 

 #if defined(_WIN32) && !defined(__CYGWIN__)

 #define vsnprintf _vsnprintf

@@ -96,9 +96,9 @@
  * that's needed to implement <resource>
  */
 #define MAX_ENTITIES 20
-char *testEntitiesName[MAX_ENTITIES];
-char *testEntitiesValue[MAX_ENTITIES];
-int nb_entities = 0;
+static char *testEntitiesName[MAX_ENTITIES];
+static char *testEntitiesValue[MAX_ENTITIES];
+static int nb_entities = 0;
 static void resetEntities(void) {
     int i;
 
@@ -205,7 +205,7 @@
     testErrors[testErrorsSize] = 0;
 }
 
-xmlXPathContextPtr ctxtXPath;
+static xmlXPathContextPtr ctxtXPath;
 
 static void
 initializeLibxml2(void) {
diff --git a/runtest.c b/runtest.c
index 3ec48cb..ac2d955 100644
--- a/runtest.c
+++ b/runtest.c
@@ -714,12 +714,12 @@
  *									*
  ************************************************************************/
 
-FILE *SAXdebug = NULL;
+static FILE *SAXdebug = NULL;
 
 /*
  * empty SAX block
  */
-xmlSAXHandler emptySAXHandlerStruct = {
+static xmlSAXHandler emptySAXHandlerStruct = {
     NULL, /* internalSubset */
     NULL, /* isStandalone */
     NULL, /* hasInternalSubset */
@@ -755,8 +755,8 @@
 };
 
 static xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
-int callbacks = 0;
-int quiet = 0;
+static int callbacks = 0;
+static int quiet = 0;
 
 /**
  * isStandaloneDebug:
@@ -1347,7 +1347,7 @@
     va_end(args);
 }
 
-xmlSAXHandler debugSAXHandlerStruct = {
+static xmlSAXHandler debugSAXHandlerStruct = {
     internalSubsetDebug,
     isStandaloneDebug,
     hasInternalSubsetDebug,
@@ -1382,7 +1382,7 @@
     NULL
 };
 
-xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
+static xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct;
 
 /*
  * SAX2 specific callbacks
@@ -1471,7 +1471,7 @@
 	fprintf(SAXdebug, ", '%s')\n", (char *) URI);
 }
 
-xmlSAXHandler debugSAX2HandlerStruct = {
+static xmlSAXHandler debugSAX2HandlerStruct = {
     internalSubsetDebug,
     isStandaloneDebug,
     hasInternalSubsetDebug,
@@ -1506,7 +1506,7 @@
     NULL
 };
 
-xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
+static xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
 
 #ifdef LIBXML_HTML_ENABLED
 /**
@@ -1586,7 +1586,7 @@
     fprintf(SAXdebug, "SAX.cdata(%s, %d)\n", output, len);
 }
 
-xmlSAXHandler debugHTMLSAXHandlerStruct = {
+static xmlSAXHandler debugHTMLSAXHandlerStruct = {
     internalSubsetDebug,
     isStandaloneDebug,
     hasInternalSubsetDebug,
@@ -1621,7 +1621,7 @@
     NULL
 };
 
-xmlSAXHandlerPtr debugHTMLSAXHandler = &debugHTMLSAXHandlerStruct;
+static xmlSAXHandlerPtr debugHTMLSAXHandler = &debugHTMLSAXHandlerStruct;
 #endif /* LIBXML_HTML_ENABLED */
 
 #ifdef LIBXML_SAX1_ENABLED
@@ -2247,8 +2247,8 @@
  *									*
  ************************************************************************/
 
-FILE *xpathOutput;
-xmlDocPtr xpathDocument;
+static FILE *xpathOutput;
+static xmlDocPtr xpathDocument;
 
 static void
 testXPath(const char *str, int xptr, int expr) {
@@ -3667,8 +3667,8 @@
     "test/threads/invalid.xml",
 };
 
-const char *Okay = "OK";
-const char *Failed = "Failed";
+static const char *Okay = "OK";
+static const char *Failed = "Failed";
 
 #ifndef xmlDoValidityCheckingDefaultValue
 #error xmlDoValidityCheckingDefaultValue is not a macro
diff --git a/schematron.c b/schematron.c
index dbf4543..dfc9a65 100644
--- a/schematron.c
+++ b/schematron.c
@@ -470,7 +470,7 @@
     ret->type = XML_STRON_CTXT_PARSER;
     ret->dict = xmlDictCreate();
     ret->URL = xmlDictLookup(ret->dict, (const xmlChar *) URL, -1);
-    ret->includes = 0;
+    ret->includes = NULL;
     ret->xctxt = xmlXPathNewContext(NULL);
     if (ret->xctxt == NULL) {
         xmlSchematronPErrMemory(NULL, "allocating schema parser XPath context",
diff --git a/testHTML.c b/testHTML.c
index 205bdf2..f350342 100644
--- a/testHTML.c
+++ b/testHTML.c
@@ -50,7 +50,7 @@
 static char *encoding = NULL;
 static int options = 0;
 
-xmlSAXHandler emptySAXHandlerStruct = {
+static xmlSAXHandler emptySAXHandlerStruct = {
     NULL, /* internalSubset */
     NULL, /* isStandalone */
     NULL, /* hasInternalSubset */
@@ -85,7 +85,7 @@
     NULL  /* xmlStructuredErrorFunc */
 };
 
-xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
+static xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
 extern xmlSAXHandlerPtr debugSAXHandler;
 
 /************************************************************************
@@ -574,7 +574,7 @@
     va_end(args);
 }
 
-xmlSAXHandler debugSAXHandlerStruct = {
+static xmlSAXHandler debugSAXHandlerStruct = {
     internalSubsetDebug,
     isStandaloneDebug,
     hasInternalSubsetDebug,
diff --git a/testReader.c b/testReader.c
index 4d5711b..8f8e26d 100644
--- a/testReader.c
+++ b/testReader.c
@@ -34,12 +34,12 @@
 
 #include <libxml/xmlreader.h>
 
-int debug = 0;
-int dump = 0;
-int noent = 0;
-int count = 0;
-int valid = 0;
-int consumed = 0;
+static int debug = 0;
+static int dump = 0;
+static int noent = 0;
+static int count = 0;
+static int valid = 0;
+static int consumed = 0;
 
 static void usage(const char *progname) {
     printf("Usage : %s [options] XMLfiles ...\n", progname);
diff --git a/testRegexp.c b/testRegexp.c
index 4f79481..1e9f35b 100644
--- a/testRegexp.c
+++ b/testRegexp.c
@@ -12,8 +12,8 @@
 #include <libxml/tree.h>
 #include <libxml/xmlregexp.h>
 
-int repeat = 0;
-int debug = 0;
+static int repeat = 0;
+static int debug = 0;
 
 static void testRegexp(xmlRegexpPtr comp, const char *value) {
     int ret;
diff --git a/testSAX.c b/testSAX.c
index 2f2921e..cd16268 100644
--- a/testSAX.c
+++ b/testSAX.c
@@ -200,7 +200,7 @@
 /*
  * empty SAX block
  */
-xmlSAXHandler emptySAXHandlerStruct = {
+static xmlSAXHandler emptySAXHandlerStruct = {
     NULL, /* internalSubset */
     NULL, /* isStandalone */
     NULL, /* hasInternalSubset */
@@ -235,7 +235,7 @@
     NULL  /* xmlStructuredErrorFunc */
 };
 
-xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
+static xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
 extern xmlSAXHandlerPtr debugSAXHandler;
 
 /************************************************************************
@@ -833,7 +833,7 @@
     va_end(args);
 }
 
-xmlSAXHandler debugSAXHandlerStruct = {
+static xmlSAXHandler debugSAXHandlerStruct = {
     internalSubsetDebug,
     isStandaloneDebug,
     hasInternalSubsetDebug,
@@ -957,7 +957,7 @@
 	fprintf(stdout, ", '%s')\n", (char *) URI);
 }
 
-xmlSAXHandler debugSAX2HandlerStruct = {
+static xmlSAXHandler debugSAX2HandlerStruct = {
     internalSubsetDebug,
     isStandaloneDebug,
     hasInternalSubsetDebug,
@@ -992,7 +992,7 @@
     NULL
 };
 
-xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
+static xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
 
 /************************************************************************
  *									*
diff --git a/testThreads.c b/testThreads.c
index 7147182..6405a77 100644
--- a/testThreads.c
+++ b/testThreads.c
@@ -36,8 +36,8 @@
     "test/threads/invalid.xml",
 };
 
-const char *Okay = "OK";
-const char *Failed = "Failed";
+static const char *Okay = "OK";
+static const char *Failed = "Failed";
 
 #ifndef xmlDoValidityCheckingDefaultValue
 #error xmlDoValidityCheckingDefaultValue is not a macro
@@ -110,7 +110,7 @@
 	}
 
 	for (i = 0; i < num_threads; i++) {
-	    ret = pthread_create(&tid[i], 0, thread_specific_data,
+	    ret = pthread_create(&tid[i], NULL, thread_specific_data,
 				 (void *) testfiles[i]);
 	    if (ret != 0) {
 		perror("pthread_create");
diff --git a/valid.c b/valid.c
index f4e05f6..32132fa 100644
--- a/valid.c
+++ b/valid.c
@@ -453,14 +453,14 @@
     xmlNodePtr ret;
 
     if (ctxt->nodeNr <= 0)
-        return (0);
+        return (NULL);
     ctxt->nodeNr--;
     if (ctxt->nodeNr > 0)
         ctxt->node = ctxt->nodeTab[ctxt->nodeNr - 1];
     else
         ctxt->node = NULL;
     ret = ctxt->nodeTab[ctxt->nodeNr];
-    ctxt->nodeTab[ctxt->nodeNr] = 0;
+    ctxt->nodeTab[ctxt->nodeNr] = NULL;
     return (ret);
 }
 
@@ -3866,7 +3866,7 @@
 	
 	fullname = xmlBuildQName(elem->name, elem->ns->prefix, fn, 50);
 	if (fullname == NULL)
-	    return(0);
+	    return(NULL);
 	attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullname, name);
 	if ((attrDecl == NULL) && (doc->extSubset != NULL)) {
 	    attrDecl = xmlGetDtdAttrDesc(doc->extSubset, fullname, name);
@@ -3951,7 +3951,7 @@
 	
 	fullname = xmlBuildQName(elem->name, elem->ns->prefix, fn, 50);
 	if (fullname == NULL)
-	    return(0);
+	    return(NULL);
 	attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullname, name);
 	if ((attrDecl == NULL) && (doc->extSubset != NULL))
 	    attrDecl = xmlGetDtdAttrDesc(doc->extSubset, fullname, name);
diff --git a/xinclude.c b/xinclude.c
index ab64096..b6ec353 100644
--- a/xinclude.c
+++ b/xinclude.c
@@ -237,7 +237,7 @@
 	ret->URI = xmlStrdup(URI);
     ret->fragment = NULL;
     ret->ref = ref;
-    ret->doc = 0;
+    ret->doc = NULL;
     ret->count = 0;
     ret->xml = 0;
     ret->inc = NULL;
@@ -360,7 +360,7 @@
     else
         ctxt->url = NULL;
     ret = ctxt->urlTab[ctxt->urlNr];
-    ctxt->urlTab[ctxt->urlNr] = 0;
+    ctxt->urlTab[ctxt->urlNr] = NULL;
     if (ret != NULL)
 	xmlFree(ret);
 }
@@ -1952,7 +1952,7 @@
 static xmlNodePtr
 xmlXIncludePreProcessNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr node) {
     xmlXIncludeAddNode(ctxt, node);
-    return(0);
+    return(NULL);
 }
 
 /**
diff --git a/xmlIO.c b/xmlIO.c
index a000e8c..0902a2f 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -1206,7 +1206,7 @@
     }
 
     /*  Set the header data.  The CRC will be needed for the trailer  */
-    buff->crc = crc32( 0L, Z_NULL, 0 );
+    buff->crc = crc32( 0L, NULL, 0 );
     hdr_lgth = snprintf( (char *)buff->zbuff, buff->size,
 			"%c%c%c%c%c%c%c%c%c%c",
 			GZ_MAGIC1, GZ_MAGIC2, Z_DEFLATED, 
diff --git a/xmllint.c b/xmllint.c
index f330539..686b652 100644
--- a/xmllint.c
+++ b/xmllint.c
@@ -235,7 +235,7 @@
     }
 }
 
-xmlExternalEntityLoader defaultEntityLoader = NULL;
+static xmlExternalEntityLoader defaultEntityLoader = NULL;
 
 static xmlParserInputPtr 
 xmllintExternalEntityLoader(const char *URL, const char *ID,
@@ -508,7 +508,7 @@
  * 			HTML ouput					*
  * 									*
  ************************************************************************/
-char buffer[50000];
+static char buffer[50000];
 
 static void
 xmlHTMLEncodeSend(void) {
@@ -817,7 +817,7 @@
 /*
  * empty SAX block
  */
-xmlSAXHandler emptySAXHandlerStruct = {
+static xmlSAXHandler emptySAXHandlerStruct = {
     NULL, /* internalSubset */
     NULL, /* isStandalone */
     NULL, /* hasInternalSubset */
@@ -852,7 +852,7 @@
     NULL  /* xmlStructuredErrorFunc */
 };
 
-xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
+static xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
 extern xmlSAXHandlerPtr debugSAXHandler;
 static int callbacks;
 
@@ -1440,7 +1440,7 @@
     va_end(args);
 }
 
-xmlSAXHandler debugSAXHandlerStruct = {
+static xmlSAXHandler debugSAXHandlerStruct = {
     internalSubsetDebug,
     isStandaloneDebug,
     hasInternalSubsetDebug,
@@ -1564,7 +1564,7 @@
 	fprintf(stdout, ", '%s')\n", (char *) URI);
 }
 
-xmlSAXHandler debugSAX2HandlerStruct = {
+static xmlSAXHandler debugSAX2HandlerStruct = {
     internalSubsetDebug,
     isStandaloneDebug,
     hasInternalSubsetDebug,
@@ -1599,7 +1599,7 @@
     NULL
 };
 
-xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
+static xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct;
 
 static void
 testSAX(const char *filename) {
diff --git a/xmlmodule.c b/xmlmodule.c
index 8b0fab9..6cc86ee 100644
--- a/xmlmodule.c
+++ b/xmlmodule.c
@@ -85,7 +85,7 @@
         __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
                         XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0,
                         name, NULL, 0, 0, "failed to open %s\n", name);
-        return 0;
+        return(NULL);
     }
 
     module->name = xmlStrdup((const xmlChar *) name);
@@ -179,7 +179,7 @@
 {
     if (NULL == module) {
         __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
-                        XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0,
+                        XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, NULL,
                         NULL, NULL, 0, 0, "null module pointer\n");
         return -1;
     }
diff --git a/xmlschemas.c b/xmlschemas.c
index 7e668cf..db30dc9 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -5023,7 +5023,7 @@
 	return (-1);
 
     if (!strchr((char *) value, ':')) {
-	ns = xmlSearchNs(attr->doc, attr->parent, 0);
+	ns = xmlSearchNs(attr->doc, attr->parent, NULL);
 	if (ns)
 	    *uri = xmlDictLookup(ctxt->dict, ns->href, -1);
 	else if (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) {
@@ -12827,7 +12827,7 @@
 			    * declaration}'s {value constraint} .
 			    */
 			    xmlSchemaGetEffectiveValueConstraint(base->attr,
-				&effFixed, &bEffValue, 0);
+				&effFixed, &bEffValue, NULL);
 			    /*
 			    * 2.1.3 ... one of the following must be true
 			    *
@@ -12839,7 +12839,7 @@
 				const xmlChar *rEffValue = NULL;
 				
 				xmlSchemaGetEffectiveValueConstraint(base->attr,
-				    &effFixed, &rEffValue, 0);
+				    &effFixed, &rEffValue, NULL);
 				    /*
 				    * 2.1.3.2 R's ·effective value constraint· is
 				    * fixed with the same string as B's.
diff --git a/xpath.c b/xpath.c
index f6e9826..f0cb291 100644
--- a/xpath.c
+++ b/xpath.c
@@ -89,7 +89,7 @@
 double xmlXPathNAN = 0;
 double xmlXPathPINF = 1;
 double xmlXPathNINF = -1;
-double xmlXPathNZERO = 0;
+static double xmlXPathNZERO = 0; /* not exported from headers */
 static int xmlXPathInitialized = 0;
 
 /**
@@ -189,6 +189,15 @@
  *									*
  ************************************************************************/
 
+/**
+ * XP_ERRORNULL:
+ * @X:  the error code
+ *
+ * Macro to raise an XPath error and return NULL.
+ */
+#define XP_ERRORNULL(X)							\
+    { xmlXPathErr(ctxt, X); return(NULL); }
+
 /*
  * The array xmlXPathErrorMessages corresponds to the enum xmlXPathError
  */
@@ -1116,20 +1125,20 @@
  *
  * Returns the XPath object just removed
  */
-extern xmlXPathObjectPtr
+xmlXPathObjectPtr
 valuePop(xmlXPathParserContextPtr ctxt)
 {
     xmlXPathObjectPtr ret;
 
     if ((ctxt == NULL) || (ctxt->valueNr <= 0))
-        return (0);
+        return (NULL);
     ctxt->valueNr--;
     if (ctxt->valueNr > 0)
         ctxt->value = ctxt->valueTab[ctxt->valueNr - 1];
     else
         ctxt->value = NULL;
     ret = ctxt->valueTab[ctxt->valueNr];
-    ctxt->valueTab[ctxt->valueNr] = 0;
+    ctxt->valueTab[ctxt->valueNr] = NULL;
     return (ret);
 }
 /**
@@ -1141,7 +1150,7 @@
  *
  * returns the number of items on the value stack
  */
-extern int
+int
 valuePush(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr value)
 {
     if ((ctxt == NULL) || (value == NULL)) return(-1);
@@ -7574,7 +7583,7 @@
 	    
 	    buffer = (xmlChar *) xmlMallocAtomic(max * sizeof(xmlChar));
 	    if (buffer == NULL) {
-		XP_ERROR0(XPATH_MEMORY_ERROR);
+		XP_ERRORNULL(XPATH_MEMORY_ERROR);
 	    }
 	    memcpy(buffer, buf, len);
 	    while ((IS_LETTER(c)) || (IS_DIGIT(c)) || /* test bigname.xml */
@@ -7587,7 +7596,7 @@
 		    buffer = (xmlChar *) xmlRealloc(buffer,
 			                            max * sizeof(xmlChar));
 		    if (buffer == NULL) {
-			XP_ERROR0(XPATH_MEMORY_ERROR);
+			XP_ERRORNULL(XPATH_MEMORY_ERROR);
 		    }
 		}
 		COPY_BUF(l,buffer,len,c);
@@ -7823,7 +7832,7 @@
 	while ((IS_CHAR_CH(CUR)) && (CUR != '"'))
 	    NEXT;
 	if (!IS_CHAR_CH(CUR)) {
-	    XP_ERROR0(XPATH_UNFINISHED_LITERAL_ERROR);
+	    XP_ERRORNULL(XPATH_UNFINISHED_LITERAL_ERROR);
 	} else {
 	    ret = xmlStrndup(q, CUR_PTR - q);
 	    NEXT;
@@ -7834,13 +7843,13 @@
 	while ((IS_CHAR_CH(CUR)) && (CUR != '\''))
 	    NEXT;
 	if (!IS_CHAR_CH(CUR)) {
-	    XP_ERROR0(XPATH_UNFINISHED_LITERAL_ERROR);
+	    XP_ERRORNULL(XPATH_UNFINISHED_LITERAL_ERROR);
 	} else {
 	    ret = xmlStrndup(q, CUR_PTR - q);
 	    NEXT;
         }
     } else {
-	XP_ERROR0(XPATH_START_LITERAL_ERROR);
+	XP_ERRORNULL(XPATH_START_LITERAL_ERROR);
     }
     return(ret);
 }
@@ -8650,7 +8659,7 @@
     if (name == NULL)
 	name = xmlXPathParseNCName(ctxt);
     if (name == NULL) {
-	XP_ERROR0(XPATH_EXPR_ERROR);
+	XP_ERRORNULL(XPATH_EXPR_ERROR);
     }
 
     blanks = IS_BLANK_CH(CUR);
@@ -8671,7 +8680,7 @@
 	else {
 	    if (name != NULL)
 		xmlFree(name);
-	    XP_ERROR0(XPATH_EXPR_ERROR);
+	    XP_ERRORNULL(XPATH_EXPR_ERROR);
 	}
 
 	*test = NODE_TEST_TYPE;
@@ -8686,7 +8695,7 @@
 	    name = NULL;
 	    if (CUR != ')') {
 		name = xmlXPathParseLiteral(ctxt);
-		CHECK_ERROR 0;
+		CHECK_ERROR NULL;
 		*test = NODE_TEST_PI;
 		SKIP_BLANKS;
 	    }
@@ -8694,7 +8703,7 @@
 	if (CUR != ')') {
 	    if (name != NULL)
 		xmlFree(name);
-	    XP_ERROR0(XPATH_UNCLOSED_ERROR);
+	    XP_ERRORNULL(XPATH_UNCLOSED_ERROR);
 	}
 	NEXT;
 	return(name);
@@ -8732,7 +8741,7 @@
 
 	name = xmlXPathParseNCName(ctxt);
 	if (name == NULL) {
-	    XP_ERROR0(XPATH_EXPR_ERROR);
+	    XP_ERRORNULL(XPATH_EXPR_ERROR);
 	}
     }
     return(name);
@@ -11390,7 +11399,7 @@
     if( pctxt->error != XPATH_EXPRESSION_OK )
     {
         xmlXPathFreeParserContext(pctxt);
-        return (0);
+        return(NULL);
     }
 
     if (*pctxt->cur != 0) {
diff --git a/xpointer.c b/xpointer.c
index 84c80c3..943cf21 100644
--- a/xpointer.c
+++ b/xpointer.c
@@ -2412,7 +2412,7 @@
 	if (pos + bytes >= len) {
 	    bytes -= (len - pos);
 	    cur = xmlXPtrAdvanceNode(cur, NULL);
-	    cur = 0;
+	    pos = 0;
 	} else if (pos + bytes < len) {
 	    pos += bytes;
 	    *node = cur;