parse: check for empty source file
authorDavid Schleef <ds@schleef.org>
Sun, 2 Oct 2011 23:25:22 +0000 (16:25 -0700)
committerDavid Schleef <ds@schleef.org>
Sun, 2 Oct 2011 23:25:22 +0000 (16:25 -0700)
orc/orcparse.c
tools/orcc.c

index 00056c3..ea17c13 100644 (file)
@@ -324,7 +324,7 @@ orc_parse_full (const char *code, OrcProgram ***programs, char **log)
   } else {
     free (parser->log);
   }
-  if (parser->programs[0]) {
+  if (parser->programs && parser->programs[0]) {
     parser->programs[0]->init_function = init_function;
   } else {
     free (init_function);
index 35dab6b..9766d02 100644 (file)
@@ -227,6 +227,11 @@ main (int argc, char *argv[])
   n_programs = n;
   printf("%s", log);
 
+  if (programs == NULL) {
+    printf("no programs\n");
+    exit(1);
+  }
+
   if (init_function == NULL) {
     init_function = orc_parse_get_init_function (programs[0]);
   }