Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash When Trying To Match "current_player" (or similar variable) To Text In If Statement #17

Open
Sopitive opened this issue Jul 29, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@Sopitive
Copy link

As mentioned in my previous issue, when you try to match current_player or a similar variable to a piece of text in an if statement (e.g. if current_player == "DutifulLake") then the program will crash if you try to compile the code like that.

@DavidJCobb
Copy link
Owner

DavidJCobb commented Aug 14, 2021

Tested and confirmed. Test-case:

for each player do
   if current_player == "DavidJCobb" then
   end
end

String literals can't be compared in this manner, and you can't access or test the name of the player that a player variable refers to; however, this should only emit a compiler error and not crash.

The crash occurs in compiler.cpp line 1618, function Compiler::_parseCondition, when attempting to assign an owning statement to the righthand side of the expression. There is no righthand side -- rhs is nullptr.

At line 1589 in the same function, we detect the case of the RHS being a string literal and emit an error; however, the error is non-fatal, and we don't return, so execution continues onward and we attempt to process the full expression as if it were valid. What we need to do instead is check if both lhs and rhs exist, immediately before we create a new Script::Comparison, and return early if either is nullptr. Aborting execution at the moment we detect a string is not ideal, as we want to make sure we can parse the whole expression if the string is on the lefthand side (i.e. we should handle each side consistently: log an error, parse the rest of the statement, and then abort on creating an in-memory statement object if the statement would not be valid).

We can expect a similar issue to exist at line 1304, in Compiler::_parseAction.

As a side note, the error message for comparing string literals is also wrong, as it was copied and pasted from the code for handling assignments.

@DavidJCobb DavidJCobb added the bug Something isn't working label Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants