From c18ba5448918a7418b3e01e1a1c5cf473efce592 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 19 Oct 2014 11:58:00 +0300 Subject: [PATCH] More resiliece against certain corner cases when direct loading An empty binary file terminated with __end was causing problems as the very first peek call would return null, causing Loader to fall back to indirect loading. However, the __end was already processed by peek, so the parse call would fail. --- source/loader.cpp | 2 +- source/parser.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/loader.cpp b/source/loader.cpp index e1a0d4a..d987a9e 100644 --- a/source/loader.cpp +++ b/source/loader.cpp @@ -87,7 +87,7 @@ void Loader::load(Parser &p) { if(p.peek(0)) load_direct(p, 0); - else + else if(p) // Peek may have processed an __end, so recheck goodness { // Parse in raw mode so we can peek immediately after a mode change Statement st = p.parse(true); diff --git a/source/parser.cpp b/source/parser.cpp index 9ad70d8..a9bbbf2 100644 --- a/source/parser.cpp +++ b/source/parser.cpp @@ -88,7 +88,7 @@ void Parser::process_control_statement(const Statement &st) const StatementKey *Parser::peek(unsigned level) { - while(1) + while(good) { const StatementKey *key = mode->peek(level); if(key && !key->keyword.compare(0, 2, "__")) @@ -96,6 +96,8 @@ const StatementKey *Parser::peek(unsigned level) else return key; } + + return 0; } bool Parser::parse_and_load(unsigned level, Loader &ldr, const LoaderAction &act) -- 2.45.2