Skip to content

Commit

Permalink
Fixed|Scripting: Edge cases in parser and slice operator
Browse files Browse the repository at this point in the history
The parser would fail if a single-line catch compound was used at the end of the script.

Slice operator would not omit the last element of the range, if trying to start past the end.
  • Loading branch information
skyjake committed Nov 20, 2019
1 parent b1e28a0 commit c4486ed
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/src/scriptsys/operatorexpression.cpp
Expand Up @@ -495,7 +495,7 @@ Value *OperatorExpression::performSlice(Value &leftValue, Value &rightValue) con
end = -1;
}

begin = clamp(0, begin, leftSize - 1);
begin = clamp(0, begin, leftSize);
end = clamp(-1, end, leftSize);

for (dint i = begin; (end >= begin && i < end) || (begin > end && i > end); i += step)
Expand Down
3 changes: 2 additions & 1 deletion doomsday/sdk/libcore/src/scriptsys/parser.cpp
Expand Up @@ -431,7 +431,8 @@ void Parser::parseTryCatchSequence(Compound &compound)
}
CatchStatement *finalCatch = nullptr;
bool expectEnd = false;
while (_statementRange.firstToken().equals(ScriptLex::CATCH))
while (!_statementRange.isEmpty() &&
_statementRange.firstToken().equals(ScriptLex::CATCH))
{
dint colon = _statementRange.find(Token::COLON);
expectEnd = (colon < 0);
Expand Down
4 changes: 3 additions & 1 deletion doomsday/tests/test_script/kitchen_sink.ds
Expand Up @@ -28,12 +28,13 @@ sections.begin('BASIC EXPRESSIONS')
sections.subsection('Basic types (number, text, array, dictionary, time).')
print 5, 5.5, -3.141592657
print 0x100, 0X123
print 'Using underscores for readability:', 0x0012_3456
print 'Using underscores for readability: %x' % 0x0012_3456
print "Hello", 'World'
print """I can span
newlines."""
print [1, 2, 3]
print [1, [2, 3], 4]
print {'a': 10, 'b': Pi}
print {'a': 'b', 1: ['b', {5:6, 6:7}], ['array', 'as', 'key']: 'oh my'}
print 'The time is now:', Time()

Expand Down Expand Up @@ -110,6 +111,7 @@ print 'a =', a
path = '/some/path/'
print 'path =', path
print 'path =', path /= 'filename.ext'
print 'path =', path

sections.subsection('Operators: []')
transports = ['planes', 'trains', 'automobiles', 'bicycles']
Expand Down

0 comments on commit c4486ed

Please sign in to comment.