Properly test for a valid identifer after #define and #undef.
[cparser] / main.c
diff --git a/main.c b/main.c
index 3479451..dcbda98 100644 (file)
--- a/main.c
+++ b/main.c
@@ -191,19 +191,19 @@ static void get_output_name(char *buf, size_t buflen, const char *inputname,
 
 static bool close_input(compilation_unit_t *unit)
 {
-       if (unit->input == NULL || unit->input == stdin)
-               return true;
-
-       if (unit->input_is_pipe) {
-               int res = pclose(unit->input);
-               if (res != EXIT_SUCCESS)
-                       return false;
+       assert(unit->input);
+       bool res;
+       if (unit->input == stdin) {
+               res = true;
+       } else if (unit->input_is_pipe) {
+               res = pclose(unit->input) == EXIT_SUCCESS;
        } else {
                fclose(unit->input);
+               res = true;
        }
        unit->input = NULL;
        unit->name  = NULL;
-       return true;
+       return res;
 }
 
 static void print_error_summary(void)
@@ -227,8 +227,7 @@ static void do_parsing(compilation_unit_t *unit)
 
        switch_pp_input(unit->input, unit->name);
        parse();
-       translation_unit_t *ast = finish_parsing();
-       unit->ast = ast;
+       unit->ast = finish_parsing();
        check_unclosed_conditionals();
        close_pp_input();
        bool res = close_input(unit);
@@ -1163,11 +1162,6 @@ static bool output_preprocessor_tokens(compilation_unit_t *unit, FILE *out)
        close_pp_input();
        print_error_summary();
        set_preprocessor_output(NULL);
-       if (unit->input != stdin) {
-               fclose(unit->input);
-               unit->input = NULL;
-               unit->name  = NULL;
-       }
 
        if (unit->type == COMPILATION_UNIT_C) {
                unit->type = COMPILATION_UNIT_PREPROCESSED_C;