]> git.draconx.ca Git - cdecl99.git/blobdiff - src/parse-decl.c
Fix use-after-free during parser error recovery.
[cdecl99.git] / src / parse-decl.c
index e96efb7073362ba47eda7e8c6341362cc1246980..694f4ab32c3875458b8293f98d619ce3b1be707c 100644 (file)
@@ -1,20 +1,21 @@
 /*
- *  Parse and validate C declarations.
- *  Copyright © 2011-2012, 2020 Nick Bowler
+ * Parse and validate C declarations.
+ * Copyright © 2011-2012, 2020 Nick Bowler
  *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
+
 #include <config.h>
 #include <stdio.h>
 #include <assert.h>
@@ -446,10 +447,12 @@ struct cdecl *cdecl_parse_decl(const char *declstr)
         * new specifier list.
         */
        norm_specs = cdecl__normalize_specs(decl->specifiers);
-
        for (struct cdecl *i = decl; i; i = i->next) {
                i->specifiers = norm_specs;
+       }
 
+       /* Now perform checks and simplifications on each declarator. */
+       for (struct cdecl *i = decl; i; i = i->next) {
                if (!forall_declarators(i, reduce_parentheses))
                        goto err;
                if (!forall_declarators(i, simplify_functions))