dcparser: Fix segfault with nested struct or switch

Fixes #1499
This commit is contained in:
rdb 2023-08-04 14:02:13 +02:00
parent c08353dea7
commit 360bf20933
3 changed files with 1165 additions and 1261 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,9 @@
/* A Bison parser, made by GNU Bison 3.1. */ /* A Bison parser, made by GNU Bison 3.8.2. */
/* Bison interface for Yacc-like parsers in C /* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015, 2018 Free Software Foundation, Inc. Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
Inc.
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -15,7 +16,7 @@
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains /* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work part or all of the Bison parser skeleton and distribute that work
@ -30,6 +31,10 @@
This special exception was added by the Free Software Foundation in This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */ version 2.2 of Bison. */
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed. */
#ifndef YY_DCYY_BUILT_TMP_DCPARSER_YXX_H_INCLUDED #ifndef YY_DCYY_BUILT_TMP_DCPARSER_YXX_H_INCLUDED
# define YY_DCYY_BUILT_TMP_DCPARSER_YXX_H_INCLUDED # define YY_DCYY_BUILT_TMP_DCPARSER_YXX_H_INCLUDED
/* Debug traces. */ /* Debug traces. */
@ -40,54 +45,63 @@
extern int dcyydebug; extern int dcyydebug;
#endif #endif
/* Token type. */ /* Token kinds. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
# define YYTOKENTYPE # define YYTOKENTYPE
enum yytokentype enum yytokentype
{ {
UNSIGNED_INTEGER = 258, YYEMPTY = -2,
SIGNED_INTEGER = 259, YYEOF = 0, /* "end of file" */
REAL = 260, YYerror = 256, /* error */
STRING = 261, YYUNDEF = 257, /* "invalid token" */
IDENTIFIER = 262, UNSIGNED_INTEGER = 258, /* UNSIGNED_INTEGER */
HEX_STRING = 263, SIGNED_INTEGER = 259, /* SIGNED_INTEGER */
KEYWORD = 264, REAL = 260, /* REAL */
KW_DCLASS = 265, STRING = 261, /* STRING */
KW_STRUCT = 266, IDENTIFIER = 262, /* IDENTIFIER */
KW_FROM = 267, HEX_STRING = 263, /* HEX_STRING */
KW_IMPORT = 268, KEYWORD = 264, /* KEYWORD */
KW_TYPEDEF = 269, KW_DCLASS = 265, /* KW_DCLASS */
KW_KEYWORD = 270, KW_STRUCT = 266, /* KW_STRUCT */
KW_SWITCH = 271, KW_FROM = 267, /* KW_FROM */
KW_CASE = 272, KW_IMPORT = 268, /* KW_IMPORT */
KW_DEFAULT = 273, KW_TYPEDEF = 269, /* KW_TYPEDEF */
KW_BREAK = 274, KW_KEYWORD = 270, /* KW_KEYWORD */
KW_INT8 = 275, KW_SWITCH = 271, /* KW_SWITCH */
KW_INT16 = 276, KW_CASE = 272, /* KW_CASE */
KW_INT32 = 277, KW_DEFAULT = 273, /* KW_DEFAULT */
KW_INT64 = 278, KW_BREAK = 274, /* KW_BREAK */
KW_UINT8 = 279, KW_INT8 = 275, /* KW_INT8 */
KW_UINT16 = 280, KW_INT16 = 276, /* KW_INT16 */
KW_UINT32 = 281, KW_INT32 = 277, /* KW_INT32 */
KW_UINT64 = 282, KW_INT64 = 278, /* KW_INT64 */
KW_FLOAT64 = 283, KW_UINT8 = 279, /* KW_UINT8 */
KW_STRING = 284, KW_UINT16 = 280, /* KW_UINT16 */
KW_BLOB = 285, KW_UINT32 = 281, /* KW_UINT32 */
KW_BLOB32 = 286, KW_UINT64 = 282, /* KW_UINT64 */
KW_INT8ARRAY = 287, KW_FLOAT64 = 283, /* KW_FLOAT64 */
KW_INT16ARRAY = 288, KW_STRING = 284, /* KW_STRING */
KW_INT32ARRAY = 289, KW_BLOB = 285, /* KW_BLOB */
KW_UINT8ARRAY = 290, KW_BLOB32 = 286, /* KW_BLOB32 */
KW_UINT16ARRAY = 291, KW_INT8ARRAY = 287, /* KW_INT8ARRAY */
KW_UINT32ARRAY = 292, KW_INT16ARRAY = 288, /* KW_INT16ARRAY */
KW_UINT32UINT8ARRAY = 293, KW_INT32ARRAY = 289, /* KW_INT32ARRAY */
KW_CHAR = 294, KW_UINT8ARRAY = 290, /* KW_UINT8ARRAY */
START_DC = 295, KW_UINT16ARRAY = 291, /* KW_UINT16ARRAY */
START_PARAMETER_VALUE = 296, KW_UINT32ARRAY = 292, /* KW_UINT32ARRAY */
START_PARAMETER_DESCRIPTION = 297 KW_UINT32UINT8ARRAY = 293, /* KW_UINT32UINT8ARRAY */
KW_CHAR = 294, /* KW_CHAR */
START_DC = 295, /* START_DC */
START_PARAMETER_VALUE = 296, /* START_PARAMETER_VALUE */
START_PARAMETER_DESCRIPTION = 297 /* START_PARAMETER_DESCRIPTION */
}; };
typedef enum yytokentype yytoken_kind_t;
#endif #endif
/* Tokens. */ /* Token kinds. */
#define YYEMPTY -2
#define YYEOF 0
#define YYerror 256
#define YYUNDEF 257
#define UNSIGNED_INTEGER 258 #define UNSIGNED_INTEGER 258
#define SIGNED_INTEGER 259 #define SIGNED_INTEGER 259
#define REAL 260 #define REAL 260
@ -134,6 +148,8 @@ extern int dcyydebug;
extern YYSTYPE dcyylval; extern YYSTYPE dcyylval;
int dcyyparse (void); int dcyyparse (void);
#endif /* !YY_DCYY_BUILT_TMP_DCPARSER_YXX_H_INCLUDED */ #endif /* !YY_DCYY_BUILT_TMP_DCPARSER_YXX_H_INCLUDED */

View File

@ -297,6 +297,7 @@ dclass_or_struct:
dclass: dclass:
KW_DCLASS optional_name KW_DCLASS optional_name
{ {
$<u.dclass>$ = current_class;
current_class = new DCClass(dc_file, $2, false, false); current_class = new DCClass(dc_file, $2, false, false);
} }
dclass_derivation '{' dclass_fields '}' dclass_derivation '{' dclass_fields '}'
@ -401,6 +402,7 @@ dclass_field:
struct: struct:
KW_STRUCT optional_name KW_STRUCT optional_name
{ {
$<u.dclass>$ = current_class;
current_class = new DCClass(dc_file, $2, true, false); current_class = new DCClass(dc_file, $2, true, false);
} }
struct_derivation '{' struct_fields '}' struct_derivation '{' struct_fields '}'
@ -488,6 +490,7 @@ struct_field:
atomic_field: atomic_field:
optional_name '(' optional_name '('
{ {
$<u.atomic>$ = current_atomic;
if (current_class == nullptr) { if (current_class == nullptr) {
yyerror("Cannot define a method outside of a struct or class."); yyerror("Cannot define a method outside of a struct or class.");
DCClass *temp_class = new DCClass(dc_file, "temp", false, false); // memory leak. DCClass *temp_class = new DCClass(dc_file, "temp", false, false); // memory leak.
@ -1243,12 +1246,13 @@ optional_name:
switch: switch:
KW_SWITCH optional_name '(' parameter_or_atomic ')' '{' KW_SWITCH optional_name '(' parameter_or_atomic ')' '{'
{ {
$<u.dswitch>$ = current_switch;
current_switch = new DCSwitch($2, $4); current_switch = new DCSwitch($2, $4);
} }
switch_fields '}' switch_fields '}'
{ {
$$ = current_switch; $$ = current_switch;
current_switch = (DCSwitch *)$<u.parameter>7; current_switch = $<u.dswitch>7;
} }
; ;