Patchwork sconfig parser bug fixes

login
register
about
Submitter Stefan Reinauer
Date 2010-08-16 18:16:52
Message ID <4C698094.90806@coresystems.de>
Download mbox | patch
Permalink /patch/1748/
State Accepted
Commit r5701
Headers show

Comments

Stefan Reinauer - 2010-08-16 18:16:52
See patch
Patrick Georgi - 2010-08-17 05:56:58
Am 16.08.2010 20:16, schrieb Stefan Reinauer:
>  See patch
For the record (I gave the Ack on IRC already):
Acked-by: Patrick Georgi <patrick.georgi@coresystems.de>

and committed by stepan in r5701

Patch

Index: util/sconfig/main.c
===================================================================
--- util/sconfig/main.c	(revision 5692)
+++ util/sconfig/main.c	(working copy)
@@ -89,7 +89,9 @@ 
 
 void yyerror (char const *str)
 {
-	fprintf (stderr, "line %d: %s\n", linenum, str);
+	extern char *yytext;
+	fprintf (stderr, "line %d: %s: %s\n", linenum + 1, yytext, str);
+	exit(1);
 }
 
 void postprocess_devtree(void) {
@@ -408,12 +410,18 @@ 
 	sprintf(headers.next->name, "mainboard/%s", mainboard);
 
 	FILE *filec = fopen(devtree, "r");
+	if (!filec) {
+		fprintf(stderr, "Could not open file '%s' for reading: ", devtree);
+		perror(NULL);
+		exit(1);
+	}
+
 	yyrestart(filec);
 
-	FILE *staticc = fopen(outputc, "w");
+	lastdev = head = &root;
 
-	lastdev = head = &root;
 	yyparse();
+
 	fclose(filec);
 
 	if ((head->type == chip) && (!head->chiph_exists)) {
@@ -422,6 +430,13 @@ 
 		while (head->next != tmp) head = head->next;
 	}
 
+	FILE *staticc = fopen(outputc, "w");
+	if (!staticc) {
+		fprintf(stderr, "Could not open file '%s' for writing: ", outputc);
+		perror(NULL);
+		exit(1);
+	}
+
 	fprintf(staticc, "#include <device/device.h>\n");
 	fprintf(staticc, "#include <device/pci.h>\n");
 	struct header *h = &headers;
@@ -435,5 +450,6 @@ 
 	walk_device_tree(staticc, &root, pass1, NULL);
 
 	fclose(staticc);
+
 	return 0;
 }