Bug Summary

File:error.c
Location:line 576, column 2
Description:Value stored to 'file' is never read

Annotated Source Code

1/*
2 * error.c: module displaying/handling XML parser errors
3 *
4 * See Copyright for the status of this software.
5 *
6 * Daniel Veillard <daniel@veillard.com>
7 */
8
9#define IN_LIBXML
10#include "libxml.h"
11
12#include <string.h>
13#include <stdarg.h>
14#include <libxml/parser.h>
15#include <libxml/xmlerror.h>
16#include <libxml/xmlmemory.h>
17#include <libxml/globals.h>
18
19void XMLCDECL xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED__attribute__((unused)),
20 const char *msg,
21 ...);
22
23#define XML_GET_VAR_STR(msg, str){ int size, prev_size = -1; int chars; char *larger; va_list ap
; str = (char *) xmlMalloc(150); if (str != ((void*)0)) { size
= 150; while (size < 64000) { __builtin_va_start(ap, msg)
; chars = vsnprintf(str, size, msg, ap); __builtin_va_end(ap)
; if ((chars > -1) && (chars < size)) { if (prev_size
== chars) { break; } else { prev_size = chars; } } if (chars
> -1) size += chars + 1; else size += 100; if ((larger = (
char *) xmlRealloc(str, size)) == ((void*)0)) { break; } str =
larger; }} }
{ \
24 int size, prev_size = -1; \
25 int chars; \
26 char *larger; \
27 va_list ap; \
28 \
29 str = (char *) xmlMalloc(150); \
30 if (str != NULL((void*)0)) { \
31 \
32 size = 150; \
33 \
34 while (size < 64000) { \
35 va_start(ap, msg)__builtin_va_start(ap, msg); \
36 chars = vsnprintf(str, size, msg, ap); \
37 va_end(ap)__builtin_va_end(ap); \
38 if ((chars > -1) && (chars < size)) { \
39 if (prev_size == chars) { \
40 break; \
41 } else { \
42 prev_size = chars; \
43 } \
44 } \
45 if (chars > -1) \
46 size += chars + 1; \
47 else \
48 size += 100; \
49 if ((larger = (char *) xmlRealloc(str, size)) == NULL((void*)0)) {\
50 break; \
51 } \
52 str = larger; \
53 }} \
54}
55
56/************************************************************************
57 * *
58 * Handling of out of context errors *
59 * *
60 ************************************************************************/
61
62/**
63 * xmlGenericErrorDefaultFunc:
64 * @ctx: an error context
65 * @msg: the message to display/transmit
66 * @...: extra parameters for the message display
67 *
68 * Default handler for out of context error messages.
69 */
70void XMLCDECL
71xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const char *msg, ...) {
72 va_list args;
73
74 if (xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())) == NULL((void*)0))
75 xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())) = (void *) stderrstderr;
76
77 va_start(args, msg)__builtin_va_start(args, msg);
78 vfprintf((FILE *)xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), msg, args);
79 va_end(args)__builtin_va_end(args);
80}
81
82/**
83 * initGenericErrorDefaultFunc:
84 * @handler: the handler
85 *
86 * Set or reset (if NULL) the default handler for generic errors
87 * to the builtin error function.
88 */
89void
90initGenericErrorDefaultFunc(xmlGenericErrorFunc * handler)
91{
92 if (handler == NULL((void*)0))
93 xmlGenericError(*(__xmlGenericError__internal_alias())) = xmlGenericErrorDefaultFunc;
94 else
95 xmlGenericError(*(__xmlGenericError__internal_alias())) = (*handler);
96}
97
98/**
99 * xmlSetGenericErrorFunc:
100 * @ctx: the new error handling context
101 * @handler: the new handler function
102 *
103 * Function to reset the handler and the error context for out of
104 * context error messages.
105 * This simply means that @handler will be called for subsequent
106 * error messages while not parsing nor validating. And @ctx will
107 * be passed as first argument to @handler
108 * One can simply force messages to be emitted to another FILE * than
109 * stderr by setting @ctx to this file handle and @handler to NULL.
110 * For multi-threaded applications, this must be set separately for each thread.
111 */
112void
113xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
114 xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())) = ctx;
115 if (handler != NULL((void*)0))
116 xmlGenericError(*(__xmlGenericError__internal_alias())) = handler;
117 else
118 xmlGenericError(*(__xmlGenericError__internal_alias())) = xmlGenericErrorDefaultFunc;
119}
120
121/**
122 * xmlSetStructuredErrorFunc:
123 * @ctx: the new error handling context
124 * @handler: the new handler function
125 *
126 * Function to reset the handler and the error context for out of
127 * context structured error messages.
128 * This simply means that @handler will be called for subsequent
129 * error messages while not parsing nor validating. And @ctx will
130 * be passed as first argument to @handler
131 * For multi-threaded applications, this must be set separately for each thread.
132 */
133void
134xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
135 xmlStructuredErrorContext(*(__xmlStructuredErrorContext())) = ctx;
136 xmlStructuredError(*(__xmlStructuredError())) = handler;
137}
138
139/************************************************************************
140 * *
141 * Handling of parsing errors *
142 * *
143 ************************************************************************/
144
145/**
146 * xmlParserPrintFileInfo:
147 * @input: an xmlParserInputPtr input
148 *
149 * Displays the associated file and line informations for the current input
150 */
151
152void
153xmlParserPrintFileInfo(xmlParserInputPtr input) {
154 if (input != NULL((void*)0)) {
155 if (input->filename)
156 xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())),
157 "%s:%d: ", input->filename,
158 input->line);
159 else
160 xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())),
161 "Entity: line %d: ", input->line);
162 }
163}
164
165/**
166 * xmlParserPrintFileContext:
167 * @input: an xmlParserInputPtr input
168 *
169 * Displays current context within the input content for error tracking
170 */
171
172static void
173xmlParserPrintFileContextInternal(xmlParserInputPtr input ,
174 xmlGenericErrorFunc channel, void *data ) {
175 const xmlChar *cur, *base;
176 unsigned int n, col; /* GCC warns if signed, because compared with sizeof() */
177 xmlChar content[81]; /* space for 80 chars + line terminator */
178 xmlChar *ctnt;
179
180 if (input == NULL((void*)0)) return;
181 cur = input->cur;
182 base = input->base;
183 /* skip backwards over any end-of-lines */
184 while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) {
185 cur--;
186 }
187 n = 0;
188 /* search backwards for beginning-of-line (to max buff size) */
189 while ((n++ < (sizeof(content)-1)) && (cur > base) &&
190 (*(cur) != '\n') && (*(cur) != '\r'))
191 cur--;
192 if ((*(cur) == '\n') || (*(cur) == '\r')) cur++;
193 /* calculate the error position in terms of the current position */
194 col = input->cur - cur;
195 /* search forward for end-of-line (to max buff size) */
196 n = 0;
197 ctnt = content;
198 /* copy selected text to our buffer */
199 while ((*cur != 0) && (*(cur) != '\n') &&
200 (*(cur) != '\r') && (n < sizeof(content)-1)) {
201 *ctnt++ = *cur++;
202 n++;
203 }
204 *ctnt = 0;
205 /* print out the selected text */
206 channel(data ,"%s\n", content);
207 /* create blank line with problem pointer */
208 n = 0;
209 ctnt = content;
210 /* (leave buffer space for pointer + line terminator) */
211 while ((n<col) && (n++ < sizeof(content)-2) && (*ctnt != 0)) {
212 if (*(ctnt) != '\t')
213 *(ctnt) = ' ';
214 ctnt++;
215 }
216 *ctnt++ = '^';
217 *ctnt = 0;
218 channel(data ,"%s\n", content);
219}
220
221/**
222 * xmlParserPrintFileContext:
223 * @input: an xmlParserInputPtr input
224 *
225 * Displays current context within the input content for error tracking
226 */
227void
228xmlParserPrintFileContext(xmlParserInputPtr input) {
229 xmlParserPrintFileContextInternal(input, xmlGenericError(*(__xmlGenericError__internal_alias())),
230 xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())));
231}
232
233/**
234 * xmlReportError:
235 * @err: the error
236 * @ctx: the parser context or NULL
237 * @str: the formatted error message
238 *
239 * Report an erro with its context, replace the 4 old error/warning
240 * routines.
241 */
242static void
243xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str,
244 xmlGenericErrorFunc channel, void *data)
245{
246 char *file = NULL((void*)0);
247 int line = 0;
248 int code = -1;
249 int domain;
250 const xmlChar *name = NULL((void*)0);
251 xmlNodePtr node;
252 xmlErrorLevel level;
253 xmlParserInputPtr input = NULL((void*)0);
254 xmlParserInputPtr cur = NULL((void*)0);
255
256 if (err == NULL((void*)0))
257 return;
258
259 if (channel == NULL((void*)0)) {
260 channel = xmlGenericError(*(__xmlGenericError__internal_alias()));
261 data = xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias()));
262 }
263 file = err->file;
264 line = err->line;
265 code = err->code;
266 domain = err->domain;
267 level = err->level;
268 node = err->node;
269
270 if (code == XML_ERR_OK)
271 return;
272
273 if ((node != NULL((void*)0)) && (node->type == XML_ELEMENT_NODE))
274 name = node->name;
275
276 /*
277 * Maintain the compatibility with the legacy error handling
278 */
279 if (ctxt != NULL((void*)0)) {
280 input = ctxt->input;
281 if ((input != NULL((void*)0)) && (input->filename == NULL((void*)0)) &&
282 (ctxt->inputNr > 1)) {
283 cur = input;
284 input = ctxt->inputTab[ctxt->inputNr - 2];
285 }
286 if (input != NULL((void*)0)) {
287 if (input->filename)
288 channel(data, "%s:%d: ", input->filename, input->line);
289 else if ((line != 0) && (domain == XML_FROM_PARSER))
290 channel(data, "Entity: line %d: ", input->line);
291 }
292 } else {
293 if (file != NULL((void*)0))
294 channel(data, "%s:%d: ", file, line);
295 else if ((line != 0) && (domain == XML_FROM_PARSER))
296 channel(data, "Entity: line %d: ", line);
297 }
298 if (name != NULL((void*)0)) {
299 channel(data, "element %s: ", name);
300 }
301 switch (domain) {
302 case XML_FROM_PARSER:
303 channel(data, "parser ");
304 break;
305 case XML_FROM_NAMESPACE:
306 channel(data, "namespace ");
307 break;
308 case XML_FROM_DTD:
309 case XML_FROM_VALID:
310 channel(data, "validity ");
311 break;
312 case XML_FROM_HTML:
313 channel(data, "HTML parser ");
314 break;
315 case XML_FROM_MEMORY:
316 channel(data, "memory ");
317 break;
318 case XML_FROM_OUTPUT:
319 channel(data, "output ");
320 break;
321 case XML_FROM_IO:
322 channel(data, "I/O ");
323 break;
324 case XML_FROM_XINCLUDE:
325 channel(data, "XInclude ");
326 break;
327 case XML_FROM_XPATH:
328 channel(data, "XPath ");
329 break;
330 case XML_FROM_XPOINTER:
331 channel(data, "parser ");
332 break;
333 case XML_FROM_REGEXP:
334 channel(data, "regexp ");
335 break;
336 case XML_FROM_MODULE:
337 channel(data, "module ");
338 break;
339 case XML_FROM_SCHEMASV:
340 channel(data, "Schemas validity ");
341 break;
342 case XML_FROM_SCHEMASP:
343 channel(data, "Schemas parser ");
344 break;
345 case XML_FROM_RELAXNGP:
346 channel(data, "Relax-NG parser ");
347 break;
348 case XML_FROM_RELAXNGV:
349 channel(data, "Relax-NG validity ");
350 break;
351 case XML_FROM_CATALOG:
352 channel(data, "Catalog ");
353 break;
354 case XML_FROM_C14N:
355 channel(data, "C14N ");
356 break;
357 case XML_FROM_XSLT:
358 channel(data, "XSLT ");
359 break;
360 case XML_FROM_I18N:
361 channel(data, "encoding ");
362 break;
363 default:
364 break;
365 }
366 switch (level) {
367 case XML_ERR_NONE:
368 channel(data, ": ");
369 break;
370 case XML_ERR_WARNING:
371 channel(data, "warning : ");
372 break;
373 case XML_ERR_ERROR:
374 channel(data, "error : ");
375 break;
376 case XML_ERR_FATAL:
377 channel(data, "error : ");
378 break;
379 }
380 if (str != NULL((void*)0)) {
381 int len;
382 len = xmlStrlenxmlStrlen__internal_alias((const xmlChar *)str);
383 if ((len > 0) && (str[len - 1] != '\n'))
384 channel(data, "%s\n", str);
385 else
386 channel(data, "%s", str);
387 } else {
388 channel(data, "%s\n", "out of memory error");
389 }
390
391 if (ctxt != NULL((void*)0)) {
392 xmlParserPrintFileContextInternal(input, channel, data);
393 if (cur != NULL((void*)0)) {
394 if (cur->filename)
395 channel(data, "%s:%d: \n", cur->filename, cur->line);
396 else if ((line != 0) && (domain == XML_FROM_PARSER))
397 channel(data, "Entity: line %d: \n", cur->line);
398 xmlParserPrintFileContextInternal(cur, channel, data);
399 }
400 }
401 if ((domain == XML_FROM_XPATH) && (err->str1 != NULL((void*)0)) &&
402 (err->int1 < 100) &&
403 (err->int1 < xmlStrlenxmlStrlen__internal_alias((const xmlChar *)err->str1))) {
404 xmlChar buf[150];
405 int i;
406
407 channel(data, "%s\n", err->str1);
408 for (i=0;i < err->int1;i++)
409 buf[i] = ' ';
410 buf[i++] = '^';
411 buf[i] = 0;
412 channel(data, "%s\n", buf);
413 }
414}
415
416/**
417 * __xmlRaiseError:
418 * @schannel: the structured callback channel
419 * @channel: the old callback channel
420 * @data: the callback data
421 * @ctx: the parser context or NULL
422 * @ctx: the parser context or NULL
423 * @domain: the domain for the error
424 * @code: the code for the error
425 * @level: the xmlErrorLevel for the error
426 * @file: the file source of the error (or NULL)
427 * @line: the line of the error or 0 if N/A
428 * @str1: extra string info
429 * @str2: extra string info
430 * @str3: extra string info
431 * @int1: extra int info
432 * @col: column number of the error or 0 if N/A
433 * @msg: the message to display/transmit
434 * @...: extra parameters for the message display
435 *
436 * Update the appropriate global or contextual error structure,
437 * then forward the error message down the parser or generic
438 * error callback handler
439 */
440void XMLCDECL
441__xmlRaiseError(xmlStructuredErrorFunc schannel,
442 xmlGenericErrorFunc channel, void *data, void *ctx,
443 void *nod, int domain, int code, xmlErrorLevel level,
444 const char *file, int line, const char *str1,
445 const char *str2, const char *str3, int int1, int col,
446 const char *msg, ...)
447{
448 xmlParserCtxtPtr ctxt = NULL((void*)0);
449 xmlNodePtr node = (xmlNodePtr) nod;
450 char *str = NULL((void*)0);
451 xmlParserInputPtr input = NULL((void*)0);
452 xmlErrorPtr to = &xmlLastError(*(__xmlLastError()));
453 xmlNodePtr baseptr = NULL((void*)0);
454
455 if ((xmlGetWarningsDefaultValue(*(__xmlGetWarningsDefaultValue())) == 0) && (level == XML_ERR_WARNING))
456 return;
457 if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) ||
458 (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) ||
459 (domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) {
460 ctxt = (xmlParserCtxtPtr) ctx;
461 if ((schannel == NULL((void*)0)) && (ctxt != NULL((void*)0)) && (ctxt->sax != NULL((void*)0)) &&
462 (ctxt->sax->initialized == XML_SAX2_MAGIC0xDEEDBEAF))
463 schannel = ctxt->sax->serror;
464 }
465 /*
466 * Check if structured error handler set
467 */
468 if (schannel == NULL((void*)0)) {
469 schannel = xmlStructuredError(*(__xmlStructuredError()));
470 /*
471 * if user has defined handler, change data ptr to user's choice
472 */
473 if (schannel != NULL((void*)0))
474 data = xmlStructuredErrorContext(*(__xmlStructuredErrorContext()));
475 }
476 if ((domain == XML_FROM_VALID) &&
477 ((channel == xmlParserValidityError) ||
478 (channel == xmlParserValidityWarning))) {
479 ctxt = (xmlParserCtxtPtr) ctx;
480 if ((schannel == NULL((void*)0)) && (ctxt != NULL((void*)0)) && (ctxt->sax != NULL((void*)0)) &&
481 (ctxt->sax->initialized == XML_SAX2_MAGIC0xDEEDBEAF))
482 schannel = ctxt->sax->serror;
483 }
484 if (code == XML_ERR_OK)
485 return;
486 /*
487 * Formatting the message
488 */
489 if (msg == NULL((void*)0)) {
490 str = (char *) xmlStrdupxmlStrdup__internal_alias(BAD_CAST(xmlChar *) "No error message provided");
491 } else {
492 XML_GET_VAR_STR(msg, str){ int size, prev_size = -1; int chars; char *larger; va_list ap
; str = (char *) xmlMalloc(150); if (str != ((void*)0)) { size
= 150; while (size < 64000) { __builtin_va_start(ap, msg)
; chars = vsnprintf(str, size, msg, ap); __builtin_va_end(ap)
; if ((chars > -1) && (chars < size)) { if (prev_size
== chars) { break; } else { prev_size = chars; } } if (chars
> -1) size += chars + 1; else size += 100; if ((larger = (
char *) xmlRealloc(str, size)) == ((void*)0)) { break; } str =
larger; }} }
;
493 }
494
495 /*
496 * specific processing if a parser context is provided
497 */
498 if (ctxt != NULL((void*)0)) {
499 if (file == NULL((void*)0)) {
500 input = ctxt->input;
501 if ((input != NULL((void*)0)) && (input->filename == NULL((void*)0)) &&
502 (ctxt->inputNr > 1)) {
503 input = ctxt->inputTab[ctxt->inputNr - 2];
504 }
505 if (input != NULL((void*)0)) {
506 file = input->filename;
507 line = input->line;
508 col = input->col;
509 }
510 }
511 to = &ctxt->lastError;
512 } else if ((node != NULL((void*)0)) && (file == NULL((void*)0))) {
513 int i;
514
515 if ((node->doc != NULL((void*)0)) && (node->doc->URL != NULL((void*)0))) {
516 baseptr = node;
517/* file = (const char *) node->doc->URL; */
518 }
519 for (i = 0;
520 ((i < 10) && (node != NULL((void*)0)) && (node->type != XML_ELEMENT_NODE));
521 i++)
522 node = node->parent;
523 if ((baseptr == NULL((void*)0)) && (node != NULL((void*)0)) &&
524 (node->doc != NULL((void*)0)) && (node->doc->URL != NULL((void*)0)))
525 baseptr = node;
526
527 if ((node != NULL((void*)0)) && (node->type == XML_ELEMENT_NODE))
528 line = node->line;
529 }
530
531 /*
532 * Save the information about the error
533 */
534 xmlResetError(to);
535 to->domain = domain;
536 to->code = code;
537 to->message = str;
538 to->level = level;
539 if (file != NULL((void*)0))
540 to->file = (char *) xmlStrdupxmlStrdup__internal_alias((const xmlChar *) file);
541 else if (baseptr != NULL((void*)0)) {
542#ifdef LIBXML_XINCLUDE_ENABLED
543 /*
544 * We check if the error is within an XInclude section and,
545 * if so, attempt to print out the href of the XInclude instead
546 * of the usual "base" (doc->URL) for the node (bug 152623).
547 */
548 xmlNodePtr prev = baseptr;
549 int inclcount = 0;
550 while (prev != NULL((void*)0)) {
551 if (prev->prev == NULL((void*)0))
552 prev = prev->parent;
553 else {
554 prev = prev->prev;
555 if (prev->type == XML_XINCLUDE_START) {
556 if (--inclcount < 0)
557 break;
558 } else if (prev->type == XML_XINCLUDE_END)
559 inclcount++;
560 }
561 }
562 if (prev != NULL((void*)0)) {
563 if (prev->type == XML_XINCLUDE_START) {
564 prev->type = XML_ELEMENT_NODE;
565 to->file = (char *) xmlGetPropxmlGetProp__internal_alias(prev, BAD_CAST(xmlChar *) "href");
566 prev->type = XML_XINCLUDE_START;
567 } else {
568 to->file = (char *) xmlGetPropxmlGetProp__internal_alias(prev, BAD_CAST(xmlChar *) "href");
569 }
570 } else
571#endif
572 to->file = (char *) xmlStrdupxmlStrdup__internal_alias(baseptr->doc->URL);
573 if ((to->file == NULL((void*)0)) && (node != NULL((void*)0)) && (node->doc != NULL((void*)0))) {
574 to->file = (char *) xmlStrdupxmlStrdup__internal_alias(node->doc->URL);
575 }
576 file = to->file;
Value stored to 'file' is never read
577 }
578 to->line = line;
579 if (str1 != NULL((void*)0))
580 to->str1 = (char *) xmlStrdupxmlStrdup__internal_alias((const xmlChar *) str1);
581 if (str2 != NULL((void*)0))
582 to->str2 = (char *) xmlStrdupxmlStrdup__internal_alias((const xmlChar *) str2);
583 if (str3 != NULL((void*)0))
584 to->str3 = (char *) xmlStrdupxmlStrdup__internal_alias((const xmlChar *) str3);
585 to->int1 = int1;
586 to->int2 = col;
587 to->node = node;
588 to->ctxt = ctx;
589
590 if (to != &xmlLastError(*(__xmlLastError())))
591 xmlCopyError(to,&xmlLastError(*(__xmlLastError())));
592
593 /*
594 * Find the callback channel if channel param is NULL
595 */
596 if ((ctxt != NULL((void*)0)) && (channel == NULL((void*)0)) &&
597 (xmlStructuredError(*(__xmlStructuredError())) == NULL((void*)0)) && (ctxt->sax != NULL((void*)0))) {
598 if (level == XML_ERR_WARNING)
599 channel = ctxt->sax->warning;
600 else
601 channel = ctxt->sax->error;
602 data = ctxt->userData;
603 } else if (channel == NULL((void*)0)) {
604 if ((schannel == NULL((void*)0)) && (xmlStructuredError(*(__xmlStructuredError())) != NULL((void*)0))) {
605 schannel = xmlStructuredError(*(__xmlStructuredError()));
606 data = xmlStructuredErrorContext(*(__xmlStructuredErrorContext()));
607 } else {
608 channel = xmlGenericError(*(__xmlGenericError__internal_alias()));
609 if (!data) {
610 data = xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias()));
611 }
612 }
613 }
614 if (schannel != NULL((void*)0)) {
615 schannel(data, to);
616 return;
617 }
618 if (channel == NULL((void*)0))
619 return;
620
621 if ((channel == xmlParserError) ||
622 (channel == xmlParserWarning) ||
623 (channel == xmlParserValidityError) ||
624 (channel == xmlParserValidityWarning))
625 xmlReportError(to, ctxt, str, NULL((void*)0), NULL((void*)0));
626 else if ((channel == (xmlGenericErrorFunc) fprintf) ||
627 (channel == xmlGenericErrorDefaultFunc))
628 xmlReportError(to, ctxt, str, channel, data);
629 else
630 channel(data, "%s", str);
631}
632
633/**
634 * __xmlSimpleError:
635 * @domain: where the error comes from
636 * @code: the error code
637 * @node: the context node
638 * @extra: extra informations
639 *
640 * Handle an out of memory condition
641 */
642void
643__xmlSimpleError(int domain, int code, xmlNodePtr node,
644 const char *msg, const char *extra)
645{
646
647 if (code == XML_ERR_NO_MEMORY) {
648 if (extra)
649 __xmlRaiseError(NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), node, domain,
650 XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL((void*)0), 0, extra,
651 NULL((void*)0), NULL((void*)0), 0, 0,
652 "Memory allocation failed : %s\n", extra);
653 else
654 __xmlRaiseError(NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), node, domain,
655 XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL((void*)0), 0, NULL((void*)0),
656 NULL((void*)0), NULL((void*)0), 0, 0, "Memory allocation failed\n");
657 } else {
658 __xmlRaiseError(NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), node, domain,
659 code, XML_ERR_ERROR, NULL((void*)0), 0, extra,
660 NULL((void*)0), NULL((void*)0), 0, 0, msg, extra);
661 }
662}
663/**
664 * xmlParserError:
665 * @ctx: an XML parser context
666 * @msg: the message to display/transmit
667 * @...: extra parameters for the message display
668 *
669 * Display and format an error messages, gives file, line, position and
670 * extra parameters.
671 */
672void XMLCDECL
673xmlParserError(void *ctx, const char *msg, ...)
674{
675 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
676 xmlParserInputPtr input = NULL((void*)0);
677 xmlParserInputPtr cur = NULL((void*)0);
678 char * str;
679
680 if (ctxt != NULL((void*)0)) {
681 input = ctxt->input;
682 if ((input != NULL((void*)0)) && (input->filename == NULL((void*)0)) &&
683 (ctxt->inputNr > 1)) {
684 cur = input;
685 input = ctxt->inputTab[ctxt->inputNr - 2];
686 }
687 xmlParserPrintFileInfo(input);
688 }
689
690 xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "error: ");
691 XML_GET_VAR_STR(msg, str){ int size, prev_size = -1; int chars; char *larger; va_list ap
; str = (char *) xmlMalloc(150); if (str != ((void*)0)) { size
= 150; while (size < 64000) { __builtin_va_start(ap, msg)
; chars = vsnprintf(str, size, msg, ap); __builtin_va_end(ap)
; if ((chars > -1) && (chars < size)) { if (prev_size
== chars) { break; } else { prev_size = chars; } } if (chars
> -1) size += chars + 1; else size += 100; if ((larger = (
char *) xmlRealloc(str, size)) == ((void*)0)) { break; } str =
larger; }} }
;
692 xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "%s", str);
693 if (str != NULL((void*)0))
694 xmlFree(str);
695
696 if (ctxt != NULL((void*)0)) {
697 xmlParserPrintFileContext(input);
698 if (cur != NULL((void*)0)) {
699 xmlParserPrintFileInfo(cur);
700 xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "\n");
701 xmlParserPrintFileContext(cur);
702 }
703 }
704}
705
706/**
707 * xmlParserWarning:
708 * @ctx: an XML parser context
709 * @msg: the message to display/transmit
710 * @...: extra parameters for the message display
711 *
712 * Display and format a warning messages, gives file, line, position and
713 * extra parameters.
714 */
715void XMLCDECL
716xmlParserWarning(void *ctx, const char *msg, ...)
717{
718 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
719 xmlParserInputPtr input = NULL((void*)0);
720 xmlParserInputPtr cur = NULL((void*)0);
721 char * str;
722
723 if (ctxt != NULL((void*)0)) {
724 input = ctxt->input;
725 if ((input != NULL((void*)0)) && (input->filename == NULL((void*)0)) &&
726 (ctxt->inputNr > 1)) {
727 cur = input;
728 input = ctxt->inputTab[ctxt->inputNr - 2];
729 }
730 xmlParserPrintFileInfo(input);
731 }
732
733 xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "warning: ");
734 XML_GET_VAR_STR(msg, str){ int size, prev_size = -1; int chars; char *larger; va_list ap
; str = (char *) xmlMalloc(150); if (str != ((void*)0)) { size
= 150; while (size < 64000) { __builtin_va_start(ap, msg)
; chars = vsnprintf(str, size, msg, ap); __builtin_va_end(ap)
; if ((chars > -1) && (chars < size)) { if (prev_size
== chars) { break; } else { prev_size = chars; } } if (chars
> -1) size += chars + 1; else size += 100; if ((larger = (
char *) xmlRealloc(str, size)) == ((void*)0)) { break; } str =
larger; }} }
;
735 xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "%s", str);
736 if (str != NULL((void*)0))
737 xmlFree(str);
738
739 if (ctxt != NULL((void*)0)) {
740 xmlParserPrintFileContext(input);
741 if (cur != NULL((void*)0)) {
742 xmlParserPrintFileInfo(cur);
743 xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "\n");
744 xmlParserPrintFileContext(cur);
745 }
746 }
747}
748
749/************************************************************************
750 * *
751 * Handling of validation errors *
752 * *
753 ************************************************************************/
754
755/**
756 * xmlParserValidityError:
757 * @ctx: an XML parser context
758 * @msg: the message to display/transmit
759 * @...: extra parameters for the message display
760 *
761 * Display and format an validity error messages, gives file,
762 * line, position and extra parameters.
763 */
764void XMLCDECL
765xmlParserValidityError(void *ctx, const char *msg, ...)
766{
767 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
768 xmlParserInputPtr input = NULL((void*)0);
769 char * str;
770 int len = xmlStrlenxmlStrlen__internal_alias((const xmlChar *) msg);
771 static int had_info = 0;
772
773 if ((len > 1) && (msg[len - 2] != ':')) {
774 if (ctxt != NULL((void*)0)) {
775 input = ctxt->input;
776 if ((input->filename == NULL((void*)0)) && (ctxt->inputNr > 1))
777 input = ctxt->inputTab[ctxt->inputNr - 2];
778
779 if (had_info == 0) {
780 xmlParserPrintFileInfo(input);
781 }
782 }
783 xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "validity error: ");
784 had_info = 0;
785 } else {
786 had_info = 1;
787 }
788
789 XML_GET_VAR_STR(msg, str){ int size, prev_size = -1; int chars; char *larger; va_list ap
; str = (char *) xmlMalloc(150); if (str != ((void*)0)) { size
= 150; while (size < 64000) { __builtin_va_start(ap, msg)
; chars = vsnprintf(str, size, msg, ap); __builtin_va_end(ap)
; if ((chars > -1) && (chars < size)) { if (prev_size
== chars) { break; } else { prev_size = chars; } } if (chars
> -1) size += chars + 1; else size += 100; if ((larger = (
char *) xmlRealloc(str, size)) == ((void*)0)) { break; } str =
larger; }} }
;
790 xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "%s", str);
791 if (str != NULL((void*)0))
792 xmlFree(str);
793
794 if ((ctxt != NULL((void*)0)) && (input != NULL((void*)0))) {
795 xmlParserPrintFileContext(input);
796 }
797}
798
799/**
800 * xmlParserValidityWarning:
801 * @ctx: an XML parser context
802 * @msg: the message to display/transmit
803 * @...: extra parameters for the message display
804 *
805 * Display and format a validity warning messages, gives file, line,
806 * position and extra parameters.
807 */
808void XMLCDECL
809xmlParserValidityWarning(void *ctx, const char *msg, ...)
810{
811 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
812 xmlParserInputPtr input = NULL((void*)0);
813 char * str;
814 int len = xmlStrlenxmlStrlen__internal_alias((const xmlChar *) msg);
815
816 if ((ctxt != NULL((void*)0)) && (len != 0) && (msg[len - 1] != ':')) {
817 input = ctxt->input;
818 if ((input->filename == NULL((void*)0)) && (ctxt->inputNr > 1))
819 input = ctxt->inputTab[ctxt->inputNr - 2];
820
821 xmlParserPrintFileInfo(input);
822 }
823
824 xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "validity warning: ");
825 XML_GET_VAR_STR(msg, str){ int size, prev_size = -1; int chars; char *larger; va_list ap
; str = (char *) xmlMalloc(150); if (str != ((void*)0)) { size
= 150; while (size < 64000) { __builtin_va_start(ap, msg)
; chars = vsnprintf(str, size, msg, ap); __builtin_va_end(ap)
; if ((chars > -1) && (chars < size)) { if (prev_size
== chars) { break; } else { prev_size = chars; } } if (chars
> -1) size += chars + 1; else size += 100; if ((larger = (
char *) xmlRealloc(str, size)) == ((void*)0)) { break; } str =
larger; }} }
;
826 xmlGenericError(*(__xmlGenericError__internal_alias()))(xmlGenericErrorContext(*(__xmlGenericErrorContext__internal_alias())), "%s", str);
827 if (str != NULL((void*)0))
828 xmlFree(str);
829
830 if (ctxt != NULL((void*)0)) {
831 xmlParserPrintFileContext(input);
832 }
833}
834
835
836/************************************************************************
837 * *
838 * Extended Error Handling *
839 * *
840 ************************************************************************/
841
842/**
843 * xmlGetLastError:
844 *
845 * Get the last global error registered. This is per thread if compiled
846 * with thread support.
847 *
848 * Returns NULL if no error occured or a pointer to the error
849 */
850xmlErrorPtr
851xmlGetLastError(void)
852{
853 if (xmlLastError(*(__xmlLastError())).code == XML_ERR_OK)
854 return (NULL((void*)0));
855 return (&xmlLastError(*(__xmlLastError())));
856}
857
858/**
859 * xmlResetError:
860 * @err: pointer to the error.
861 *
862 * Cleanup the error.
863 */
864void
865xmlResetError(xmlErrorPtr err)
866{
867 if (err == NULL((void*)0))
868 return;
869 if (err->code == XML_ERR_OK)
870 return;
871 if (err->message != NULL((void*)0))
872 xmlFree(err->message);
873 if (err->file != NULL((void*)0))
874 xmlFree(err->file);
875 if (err->str1 != NULL((void*)0))
876 xmlFree(err->str1);
877 if (err->str2 != NULL((void*)0))
878 xmlFree(err->str2);
879 if (err->str3 != NULL((void*)0))
880 xmlFree(err->str3);
881 memset(err, 0, sizeof(xmlError));
882 err->code = XML_ERR_OK;
883}
884
885/**
886 * xmlResetLastError:
887 *
888 * Cleanup the last global error registered. For parsing error
889 * this does not change the well-formedness result.
890 */
891void
892xmlResetLastError(void)
893{
894 if (xmlLastError(*(__xmlLastError())).code == XML_ERR_OK)
895 return;
896 xmlResetError(&xmlLastError(*(__xmlLastError())));
897}
898
899/**
900 * xmlCtxtGetLastError:
901 * @ctx: an XML parser context
902 *
903 * Get the last parsing error registered.
904 *
905 * Returns NULL if no error occured or a pointer to the error
906 */
907xmlErrorPtr
908xmlCtxtGetLastError(void *ctx)
909{
910 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
911
912 if (ctxt == NULL((void*)0))
913 return (NULL((void*)0));
914 if (ctxt->lastError.code == XML_ERR_OK)
915 return (NULL((void*)0));
916 return (&ctxt->lastError);
917}
918
919/**
920 * xmlCtxtResetLastError:
921 * @ctx: an XML parser context
922 *
923 * Cleanup the last global error registered. For parsing error
924 * this does not change the well-formedness result.
925 */
926void
927xmlCtxtResetLastError(void *ctx)
928{
929 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
930
931 if (ctxt == NULL((void*)0))
932 return;
933 if (ctxt->lastError.code == XML_ERR_OK)
934 return;
935 xmlResetError(&ctxt->lastError);
936}
937
938/**
939 * xmlCopyError:
940 * @from: a source error
941 * @to: a target error
942 *
943 * Save the original error to the new place.
944 *
945 * Returns 0 in case of success and -1 in case of error.
946 */
947int
948xmlCopyError(xmlErrorPtr from, xmlErrorPtr to) {
949 char *message, *file, *str1, *str2, *str3;
950
951 if ((from == NULL((void*)0)) || (to == NULL((void*)0)))
952 return(-1);
953
954 message = (char *) xmlStrdupxmlStrdup__internal_alias((xmlChar *) from->message);
955 file = (char *) xmlStrdupxmlStrdup__internal_alias ((xmlChar *) from->file);
956 str1 = (char *) xmlStrdupxmlStrdup__internal_alias ((xmlChar *) from->str1);
957 str2 = (char *) xmlStrdupxmlStrdup__internal_alias ((xmlChar *) from->str2);
958 str3 = (char *) xmlStrdupxmlStrdup__internal_alias ((xmlChar *) from->str3);
959
960 if (to->message != NULL((void*)0))
961 xmlFree(to->message);
962 if (to->file != NULL((void*)0))
963 xmlFree(to->file);
964 if (to->str1 != NULL((void*)0))
965 xmlFree(to->str1);
966 if (to->str2 != NULL((void*)0))
967 xmlFree(to->str2);
968 if (to->str3 != NULL((void*)0))
969 xmlFree(to->str3);
970 to->domain = from->domain;
971 to->code = from->code;
972 to->level = from->level;
973 to->line = from->line;
974 to->node = from->node;
975 to->int1 = from->int1;
976 to->int2 = from->int2;
977 to->node = from->node;
978 to->ctxt = from->ctxt;
979 to->message = message;
980 to->file = file;
981 to->str1 = str1;
982 to->str2 = str2;
983 to->str3 = str3;
984
985 return 0;
986}
987
988#define bottom_error
989#include "elfgcchack.h"