From 3cc5c198b4f417c02c66b9f73707207923fed7aa Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 8 Nov 2014 17:39:43 -0800 Subject: [PATCH] Allow dynamic char arrays. --- sourcepawn/compiler/sc1.cpp | 4 +++- sourcepawn/compiler/tests/ok-dynamic-char.sp | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 sourcepawn/compiler/tests/ok-dynamic-char.sp diff --git a/sourcepawn/compiler/sc1.cpp b/sourcepawn/compiler/sc1.cpp index a4b9c279..03885ac1 100644 --- a/sourcepawn/compiler/sc1.cpp +++ b/sourcepawn/compiler/sc1.cpp @@ -2171,7 +2171,7 @@ static void declloc(int tokid) // // For now, we only implement the string literal initializer. if (type->is_new && needtoken('=')) { - if (type->isCharArray()) { + if (type->isCharArray() && !lexpeek(tNEW)) { // Error if we're assigning something other than a string literal. needtoken(tSTRING); @@ -2205,6 +2205,8 @@ static void declloc(int tokid) TRUE, FALSE, TRUE, FALSE, &type->idxtag[i], &child, 0, &val); + if (i == type->numdim - 1 && type->tag == pc_tag_string) + stradjust(sPRI); pushreg(sPRI); switch (ident) { diff --git a/sourcepawn/compiler/tests/ok-dynamic-char.sp b/sourcepawn/compiler/tests/ok-dynamic-char.sp new file mode 100644 index 00000000..88c7b281 --- /dev/null +++ b/sourcepawn/compiler/tests/ok-dynamic-char.sp @@ -0,0 +1,5 @@ + +public OnPluginStart() +{ + char[] x = new char[500]; +}