@@ -245,24 +245,6 @@ xmlErrParser(xmlParserCtxtPtr ctxt, xmlNodePtr node,
245245 va_end (ap );
246246}
247247
248- /**
249- * __xmlErrEncoding:
250- * @ctxt: an XML parser context
251- * @xmlerr: the error number
252- * @msg: the error message
253- * @str1: an string info
254- * @str2: an string info
255- *
256- * Handle an encoding error
257- */
258- void
259- __xmlErrEncoding (xmlParserCtxtPtr ctxt , xmlParserErrors xmlerr ,
260- const char * msg , const xmlChar * str1 , const xmlChar * str2 )
261- {
262- xmlErrParser (ctxt , NULL , XML_FROM_PARSER , xmlerr , XML_ERR_FATAL ,
263- str1 , str2 , NULL , 0 , msg , str1 , str2 );
264- }
265-
266248/**
267249 * xmlErrInternal:
268250 * @ctxt: an XML parser context
@@ -659,21 +641,7 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
659641encoding_error :
660642 /* Only report the first error */
661643 if ((ctxt -> input -> flags & XML_INPUT_ENCODING_ERROR ) == 0 ) {
662- if ((ctxt == NULL ) || (ctxt -> input == NULL ) ||
663- (ctxt -> input -> end - ctxt -> input -> cur < 4 )) {
664- __xmlErrEncoding (ctxt , XML_ERR_INVALID_CHAR ,
665- "Input is not proper UTF-8, indicate encoding !\n" ,
666- NULL , NULL );
667- } else {
668- char buffer [150 ];
669-
670- snprintf (buffer , 149 , "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n" ,
671- ctxt -> input -> cur [0 ], ctxt -> input -> cur [1 ],
672- ctxt -> input -> cur [2 ], ctxt -> input -> cur [3 ]);
673- __xmlErrEncoding (ctxt , XML_ERR_INVALID_CHAR ,
674- "Input is not proper UTF-8, indicate encoding !\n%s" ,
675- BAD_CAST buffer , NULL );
676- }
644+ xmlCtxtErrIO (ctxt , XML_ERR_INVALID_ENCODING , NULL );
677645 ctxt -> input -> flags |= XML_INPUT_ENCODING_ERROR ;
678646 }
679647 ctxt -> input -> cur ++ ;
@@ -809,20 +777,7 @@ xmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
809777encoding_error :
810778 /* Only report the first error */
811779 if ((ctxt -> input -> flags & XML_INPUT_ENCODING_ERROR ) == 0 ) {
812- if (ctxt -> input -> end - ctxt -> input -> cur < 4 ) {
813- __xmlErrEncoding (ctxt , XML_ERR_INVALID_CHAR ,
814- "Input is not proper UTF-8, indicate encoding !\n" ,
815- NULL , NULL );
816- } else {
817- char buffer [150 ];
818-
819- snprintf (& buffer [0 ], 149 , "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n" ,
820- ctxt -> input -> cur [0 ], ctxt -> input -> cur [1 ],
821- ctxt -> input -> cur [2 ], ctxt -> input -> cur [3 ]);
822- __xmlErrEncoding (ctxt , XML_ERR_INVALID_CHAR ,
823- "Input is not proper UTF-8, indicate encoding !\n%s" ,
824- BAD_CAST buffer , NULL );
825- }
780+ xmlCtxtErrIO (ctxt , XML_ERR_INVALID_ENCODING , NULL );
826781 ctxt -> input -> flags |= XML_INPUT_ENCODING_ERROR ;
827782 }
828783 * len = 1 ;
@@ -1050,14 +1005,9 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
10501005 }
10511006
10521007 if (res != 0 ) {
1053- if (res == XML_ERR_UNSUPPORTED_ENCODING ) {
1054- const char * name = xmlGetCharEncodingName (enc );
1008+ const char * name = xmlGetCharEncodingName (enc );
10551009
1056- __xmlErrEncoding (ctxt , res , "encoding not supported: %s\n" ,
1057- BAD_CAST (name ? name : "<null>" ), NULL );
1058- } else {
1059- xmlFatalErr (ctxt , res , NULL );
1060- }
1010+ xmlFatalErr (ctxt , res , (name ? name : "<null>" ));
10611011 return (-1 );
10621012 }
10631013
@@ -1090,13 +1040,12 @@ xmlSwitchEncodingName(xmlParserCtxtPtr ctxt, const char *encoding) {
10901040 xmlCharEncodingHandlerPtr handler ;
10911041 int res ;
10921042
1043+ if (encoding == NULL )
1044+ return (-1 );
1045+
10931046 res = xmlOpenCharEncodingHandler (encoding , & handler );
10941047 if (res != 0 ) {
1095- if (res == XML_ERR_UNSUPPORTED_ENCODING )
1096- __xmlErrEncoding (ctxt , res , "Unsupported encoding: %s\n" ,
1097- (const xmlChar * ) encoding , NULL );
1098- else
1099- xmlFatalErr (ctxt , res , NULL );
1048+ xmlFatalErr (ctxt , res , encoding );
11001049 return (-1 );
11011050 }
11021051
@@ -1188,9 +1137,7 @@ xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
11881137 if (nbchars == XML_ENC_ERR_MEMORY ) {
11891138 xmlErrMemory (ctxt );
11901139 } else if (nbchars < 0 ) {
1191- xmlErrInternal (ctxt ,
1192- "switching encoding: encoder error\n" ,
1193- NULL );
1140+ xmlCtxtErrIO (ctxt , in -> error , NULL );
11941141 xmlHaltParser (ctxt );
11951142 return (-1 );
11961143 }
0 commit comments