From 8dc081a60dec3a0b7df2126349e3f57ee2933e89 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Wed, 25 Mar 2020 19:52:22 +0100 Subject: [PATCH 1/3] ignore unterminated empty strings --- components/compiler/scanner.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/compiler/scanner.cpp b/components/compiler/scanner.cpp index 6d66b0493..24c13a1d2 100644 --- a/components/compiler/scanner.cpp +++ b/components/compiler/scanner.cpp @@ -282,6 +282,8 @@ namespace Compiler if (!scanName (name)) return false; + else if(name.empty()) + return true; TokenLoc loc (mLoc); mLoc.mLiteral.clear(); @@ -366,6 +368,13 @@ namespace Compiler { if (mIgnoreNewline) mErrorHandler.warning ("string contains newline character, make sure that it is intended", mLoc); + else if (name.size() == 1 || name.size() == 2 && name[1] == '\r') + { + name.clear(); + mLoc.mLiteral.clear(); + mErrorHandler.warning ("unterminated empty string", mLoc); + break; + } else { error = true; From fea7e68fe9bcaca9c77353cdd452118b47b4cc14 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Wed, 25 Mar 2020 20:34:08 +0100 Subject: [PATCH 2/3] silence operator precedence warning --- components/compiler/scanner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/compiler/scanner.cpp b/components/compiler/scanner.cpp index 24c13a1d2..b06d683f7 100644 --- a/components/compiler/scanner.cpp +++ b/components/compiler/scanner.cpp @@ -368,7 +368,7 @@ namespace Compiler { if (mIgnoreNewline) mErrorHandler.warning ("string contains newline character, make sure that it is intended", mLoc); - else if (name.size() == 1 || name.size() == 2 && name[1] == '\r') + else if (name.size() == 1 || (name.size() == 2 && name[1] == '\r')) { name.clear(); mLoc.mLiteral.clear(); From e07fa37fa35a2d25dc9b0ddd4eefab676e772442 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 29 Mar 2020 22:29:22 +0200 Subject: [PATCH 3/3] ignore final whitespace/comments --- CHANGELOG.md | 1 + components/compiler/scanner.cpp | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85fffdd1f..0b559c23f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -207,6 +207,7 @@ Bug #5300: NPCs don't switch from torch to shield when starting combat Bug #5308: World map copying makes save loading much slower Bug #5313: Node properties of identical type are not applied in the correct order + Bug #5345: Dopey Necromancy does not work due to a missing quote Feature #1774: Handle AvoidNode Feature #2229: Improve pathfinding AI Feature #3025: Analogue gamepad movement controls diff --git a/components/compiler/scanner.cpp b/components/compiler/scanner.cpp index b06d683f7..83686e4c1 100644 --- a/components/compiler/scanner.cpp +++ b/components/compiler/scanner.cpp @@ -368,15 +368,28 @@ namespace Compiler { if (mIgnoreNewline) mErrorHandler.warning ("string contains newline character, make sure that it is intended", mLoc); - else if (name.size() == 1 || (name.size() == 2 && name[1] == '\r')) - { - name.clear(); - mLoc.mLiteral.clear(); - mErrorHandler.warning ("unterminated empty string", mLoc); - break; - } else { + bool allWhitespace = true; + for (size_t i = 1; i < name.size(); i++) + { + //ignore comments + if (name[i] == ';') + break; + else if (name[i] != '\t' && name[i] != ' ' && name[i] != '\r') + { + allWhitespace = false; + break; + } + } + if (allWhitespace) + { + name.clear(); + mLoc.mLiteral.clear(); + mErrorHandler.warning ("unterminated empty string", mLoc); + return true; + } + error = true; mErrorHandler.error ("incomplete string or name", mLoc); break;