[PATCH wayland 1/2] scanner: Improve XML parse error reporting

Jonas Ådahl jadahl at gmail.com
Mon Sep 22 13:11:18 PDT 2014


Print the parse error and exit with a failure if expat can't parse the
XML.

Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
---
 src/scanner.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/scanner.c b/src/scanner.c
index 72fd3e8..6be1d7a 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -1296,8 +1296,14 @@ int main(int argc, char *argv[])
 			fprintf(stderr, "fread: %m\n");
 			exit(EXIT_FAILURE);
 		}
-		XML_ParseBuffer(ctx.parser, len, len == 0);
-
+		if (XML_ParseBuffer(ctx.parser, len, len == 0) == 0) {
+			fprintf(stderr,
+				"Error parsing XML at line %ld col %ld: %s\n",
+				XML_GetCurrentLineNumber(ctx.parser),
+				XML_GetCurrentColumnNumber(ctx.parser),
+				XML_ErrorString(XML_GetErrorCode(ctx.parser)));
+			exit(EXIT_FAILURE);
+		}
 	} while (len > 0);
 
 	XML_ParserFree(ctx.parser);
-- 
1.8.5.1



More information about the wayland-devel mailing list