fixed problem when no initial "chunk" was given to xmlCreatePushParser

* parser.c: fixed problem when no initial "chunk" was
  given to xmlCreatePushParser (bug 162613)
diff --git a/ChangeLog b/ChangeLog
index 9ec4cc1..11d4c79 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Feb 11 22:20:41 HKT 2005 William Brack <wbrack@mmm.com.hk>
+
+	* parser.c: fixed problem when no initial "chunk" was
+	  given to xmlCreatePushParser (bug 162613)
+
 Fri Feb 11 18:37:22 HKT 2005 William Brack <wbrack@mmm.com.hk>
 
 	* dict.c: fixed compilation warning
diff --git a/parser.c b/parser.c
index f382087..d089882 100644
--- a/parser.c
+++ b/parser.c
@@ -9272,16 +9272,16 @@
 		    /* 
 		     * Get the 4 first bytes and decode the charset
 		     * if enc != XML_CHAR_ENCODING_NONE
-		     * plug some encoding conversion routines.
+		     * plug some encoding conversion routines,
+		     * else xmlSwitchEncoding will set to (default)
+		     * UTF8.
 		     */
 		    start[0] = RAW;
 		    start[1] = NXT(1);
 		    start[2] = NXT(2);
 		    start[3] = NXT(3);
 		    enc = xmlDetectCharEncoding(start, 4);
-		    if (enc != XML_CHAR_ENCODING_NONE) {
-			xmlSwitchEncoding(ctxt, enc);
-		    }
+		    xmlSwitchEncoding(ctxt, enc);
 		    break;
 		}
 
@@ -10239,8 +10239,14 @@
 
     inputPush(ctxt, inputStream);
 
-    if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
-        (ctxt->input->buf != NULL))  {	      
+    /*
+     * If the caller didn't provide an initial 'chunk' for determining
+     * the encoding, we set the context to XML_CHAR_ENCODING_NONE so
+     * that it can be automatically determined later
+     */
+    if ((size == 0) || (chunk == NULL)) {
+	ctxt->charset = XML_CHAR_ENCODING_NONE;
+    } else if ((ctxt->input != NULL) && (ctxt->input->buf != NULL)) {
 	int base = ctxt->input->base - ctxt->input->buf->buffer->content;
 	int cur = ctxt->input->cur - ctxt->input->base;