more fixes. Daniel

* parser.c testapi.c xmlIO.c xmlstring.c: more fixes.
Daniel
diff --git a/ChangeLog b/ChangeLog
index 9c8217c..680d673 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Mon Nov  8 12:55:16 CET 2004 Daniel Veillard <daniel@veillard.com>
+
+	* parser.c testapi.c xmlIO.c xmlstring.c: more fixes.
+
 Mon Nov  8 11:24:57 CET 2004 Daniel Veillard <daniel@veillard.com>
 
 	* gentest.py testapi.c: more types, more coverage
diff --git a/parser.c b/parser.c
index 7399bfc..05c31a9 100644
--- a/parser.c
+++ b/parser.c
@@ -9978,7 +9978,11 @@
 	    xmlFreeParserCtxt(ctxt);
 	    return(NULL);
 	}
-	memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler));
+	memset(ctxt->sax, 0, sizeof(xmlSAXHandler));
+	if (sax->initialized == XML_SAX2_MAGIC)
+	    memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler));
+	else
+	    memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));
 	if (user_data != NULL)
 	    ctxt->userData = user_data;
     }	
@@ -10081,7 +10085,11 @@
 	    xmlFree(ctxt);
 	    return(NULL);
 	}
-	memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler));
+	memset(ctxt->sax, 0, sizeof(xmlSAXHandler));
+	if (sax->initialized == XML_SAX2_MAGIC)
+	    memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler));
+	else
+	    memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));
 	if (user_data != NULL)
 	    ctxt->userData = user_data;
     }	
diff --git a/testapi.c b/testapi.c
index 6708ce5..10a5ddd 100644
--- a/testapi.c
+++ b/testapi.c
@@ -20,7 +20,7 @@
 static int call_tests = 0;
 static int function_tests = 0;
 
-static xmlChar chartab[1024] = "  chartab\n";
+static xmlChar chartab[1024];
 static int inttab[1024];
 static unsigned long longtab[1024];
 
@@ -110,6 +110,11 @@
     int ret;
     int blocks, mem;
 
+    memset(chartab, 0, sizeof(chartab));
+    strncpy(chartab, "  chartab\n", 20);
+    memset(inttab, 0, sizeof(inttab));
+    memset(longtab, 0, sizeof(longtab));
+
     xmlInitParser();
 #ifdef LIBXML_SCHEMAS_ENABLED
     xmlRelaxNGInitTypes();
diff --git a/xmlIO.c b/xmlIO.c
index 8528194..1ca80c9 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -420,7 +420,8 @@
 	    channel = ctxt->sax->warning;
 	    level = XML_ERR_WARNING;
 	}
-	schannel = ctxt->sax->serror;
+	if (ctxt->sax->initialized == XML_SAX2_MAGIC)
+	    schannel = ctxt->sax->serror;
 	data = ctxt->userData;
     }
     __xmlRaiseError(schannel, channel, data, ctxt, NULL, XML_FROM_IO,
@@ -1549,6 +1550,7 @@
  */
 int 
 xmlIOHTTPRead(void * context, char * buffer, int len) {
+    if ((buffer == NULL) || (len < 0)) return(-1);
     return(xmlNanoHTTPRead(context, &buffer[0], len));
 }
 
@@ -1827,6 +1829,7 @@
  */
 int 
 xmlIOFTPRead(void * context, char * buffer, int len) {
+    if ((buffer == NULL) || (len < 0)) return(-1);
     return(xmlNanoFTPRead(context, &buffer[0], len));
 }
 
diff --git a/xmlstring.c b/xmlstring.c
index a4dc44c..db94432 100644
--- a/xmlstring.c
+++ b/xmlstring.c
@@ -92,8 +92,10 @@
         xmlErrMemory(NULL, NULL);
         return(NULL);
     }
-    for (i = 0;i < len;i++)
+    for (i = 0;i < len;i++) {
         ret[i] = (xmlChar) cur[i];
+        if (ret[i] == 0) return(ret);
+    }
     ret[len] = 0;
     return(ret);
 }
@@ -809,6 +811,7 @@
  * @len:  the number of characters in the array
  *
  * storage size of an UTF8 string
+ * the behaviour is not garanteed if the input string is not UTF-8
  *
  * Returns the storage size of
  * the first 'len' characters of ARRAY
@@ -829,8 +832,10 @@
         if ( !*ptr )
             break;
         if ( (ch = *ptr++) & 0x80)
-            while ( (ch<<=1) & 0x80 )
+            while ((ch<<=1) & 0x80 ) {
                 ptr++;
+		if (*ptr == 0) break;
+	    }
     }
     return (ptr - utf);
 }