From 3dd57f79813f4a253644396172320293e53e932c Mon Sep 17 00:00:00 2001 From: "William M. Brack" Date: Tue, 13 May 2003 02:06:18 +0000 Subject: Fixed bug 109942 --- error.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'error.c') diff --git a/error.c b/error.c index 96666932..f709bbd0 100644 --- a/error.c +++ b/error.c @@ -149,8 +149,8 @@ xmlParserPrintFileInfo(xmlParserInputPtr input) { void xmlParserPrintFileContext(xmlParserInputPtr input) { const xmlChar *cur, *base; - int n; - xmlChar content[81]; + int n, col; + xmlChar content[81]; /* space for 80 chars + line terminator */ xmlChar *ctnt; if (input == NULL) return; @@ -161,37 +161,34 @@ xmlParserPrintFileContext(xmlParserInputPtr input) { cur--; } n = 0; - /* search backwards for beginning-of-line maximum 80 characters */ - while ((n++ < 80) && (cur > base) && (*cur != '\n') && (*cur != '\r')) + /* search backwards for beginning-of-line (to max buff size) */ + while ((n++ < sizeof(content)-1) && (cur > base) && (*cur != '\n') && (*cur != '\r')) cur--; if ((*cur == '\n') || (*cur == '\r')) cur++; - /* search forward for end-of-line maximum 80 characters */ + /* calculate the error position in terms of the current position */ + col = input->cur - cur; + /* search forward for end-of-line (to max buff size) */ n = 0; ctnt = content; - while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) { + /* copy selected text to our buffer */ + while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < sizeof(content)-1)) { *ctnt++ = *cur++; n++; } *ctnt = 0; + /* print out the selected text */ xmlGenericError(xmlGenericErrorContext,"%s\n", content); /* create blank line with problem pointer */ - cur = input->cur; - while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) { - cur--; - } n = 0; ctnt = content; - while ((n++ < 79) && (cur > base) && (*cur != '\n') && (*cur != '\r')) { - *ctnt++ = ' '; - cur--; - } - if (ctnt > content) { - *(--ctnt) = '^'; - *(++ctnt) = 0; - } else { - *ctnt = '^'; - *(++ctnt) = 0; + /* (leave buffer space for pointer + line terminator) */ + while ((n