Skip to content
Permalink
Browse files

Aul: Correctly check for enable/disable keywords in warning pragma

The parser was only checking that the passed setting matched the
beginning of the expected keyword, instead of checking for the full
length. This way, users could write "#warning e" instead of the
expected "#warning enable" and still have it work.
  • Loading branch information...
isilkor committed Feb 17, 2019
1 parent c8d22e3 commit a0c9bfd931e42ab6ef95e12b24be1d072cf5b3a6
Showing with 6 additions and 2 deletions.
  1. +2 −2 src/script/C4AulParse.cpp
  2. +4 −0 tests/aul/AulSyntaxTest.cpp
@@ -791,11 +791,11 @@ void C4AulParse::Parse_WarningPragma()
auto start = cursor;
cursor = std::find_if(start, end, IsWhiteSpace);
bool enable_warning = false;
if (std::equal(start, cursor, C4Aul_Warning_enable))
if (cursor - start == sizeof(C4Aul_Warning_enable) - 1 && std::equal(start, cursor, C4Aul_Warning_enable))
{
enable_warning = true;
}
else if (std::equal(start, cursor, C4Aul_Warning_disable))
else if (cursor - start == sizeof(C4Aul_Warning_disable) - 1 && std::equal(start, cursor, C4Aul_Warning_disable))
{
enable_warning = false;
}
@@ -94,6 +94,10 @@ TEST(AulSyntaxTest, PragmaWarningWithInsufficientData)
EXPECT_THROW(ParseScript("#warning\n"), C4AulParseError);
EXPECT_THROW(ParseScript("#warning "), C4AulParseError);
EXPECT_THROW(ParseScript("#warning \n"), C4AulParseError);
EXPECT_THROW(ParseScript("#warning e"), C4AulParseError);
EXPECT_THROW(ParseScript("#warning enabl"), C4AulParseError);
EXPECT_THROW(ParseScript("#warning d"), C4AulParseError);
EXPECT_THROW(ParseScript("#warning disabl"), C4AulParseError);
}

using namespace ::aul::ast;

0 comments on commit a0c9bfd

Please sign in to comment.
You can’t perform that action at this time.