From 046f167b6e49e4718cfc2597a40ffbfb7d1769b3 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 9 Nov 2014 00:12:44 -0800 Subject: [PATCH] Fix a bug where local dynamic array declarations could be mistakenly parsed as old decls (bug 6279). --- sourcepawn/compiler/sc.h | 2 ++ sourcepawn/compiler/sc1.cpp | 6 +++++- sourcepawn/compiler/tests/ok-local-dynamic-bool.sp | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 sourcepawn/compiler/tests/ok-local-dynamic-bool.sp diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index 91a2ff1c..1c02741f 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -271,6 +271,7 @@ typedef struct svalue_s { #define DECLFLAG_DYNAMIC_ARRAYS 0x20 // Dynamic arrays are allowed. #define DECLFLAG_OLD 0x40 // Known old-style declaration. #define DECLFLAG_FIELD 0x80 // Struct field. +#define DECLFLAG_NEW 0x100 // Known new-style declaration. #define DECLMASK_NAMED_DECL (DECLFLAG_ARGUMENT | DECLFLAG_VARIABLE | DECLFLAG_MAYBE_FUNCTION | DECLFLAG_FIELD) typedef struct { @@ -469,6 +470,7 @@ enum TokenKind { tENDLESS, /* endless loop, for assigment to "lastst" only */ tEMPTYBLOCK, /* empty blocks for AM bug 4825 */ tEOL, /* newline, only returned by peek_new_line() */ + tNEWDECL, /* for declloc() */ tLAST_TOKEN_ID }; diff --git a/sourcepawn/compiler/sc1.cpp b/sourcepawn/compiler/sc1.cpp index 959fb02d..796226ff 100644 --- a/sourcepawn/compiler/sc1.cpp +++ b/sourcepawn/compiler/sc1.cpp @@ -2096,6 +2096,8 @@ static void declloc(int tokid) int declflags = DECLFLAG_VARIABLE | DECLFLAG_ENUMROOT | DECLFLAG_DYNAMIC_ARRAYS; if (tokid == tNEW || tokid == tDECL) declflags |= DECLFLAG_OLD; + else if (tokid == tNEWDECL) + declflags |= DECLFLAG_NEW; parse_decl(&decl, declflags); @@ -3499,6 +3501,8 @@ int parse_decl(declinfo_t *decl, int flags) // example, if preceded by tNEW or tDECL. if (flags & DECLFLAG_OLD) return parse_old_decl(decl, flags); + if (flags & DECLFLAG_NEW) + return parse_new_decl(decl, NULL, flags); // If parsing an argument, there are two simple checks for whether this is a // new or old-style declaration. @@ -6791,7 +6795,7 @@ static void statement(int *lastindent,int allow_decl) lexpush(); autozero = TRUE; lastst = tNEW; - declloc(tok); + declloc(tNEWDECL); return; } } diff --git a/sourcepawn/compiler/tests/ok-local-dynamic-bool.sp b/sourcepawn/compiler/tests/ok-local-dynamic-bool.sp new file mode 100644 index 00000000..454d68b0 --- /dev/null +++ b/sourcepawn/compiler/tests/ok-local-dynamic-bool.sp @@ -0,0 +1,5 @@ +public int main() +{ + bool[] egg = new bool[10]; +} +