From 9f2c31149ac46236a36595fd3061c131f4d47ded Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Sun, 6 Jun 2021 19:17:02 +0800 Subject: [PATCH] bug fixed fixed SIGSEGV when failed to load file in nasal_lexer::openfile --- main.cpp | 2 ++ nasal_import.h | 7 ++++--- nasal_lexer.h | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 4951747..e0c7f9d 100644 --- a/main.cpp +++ b/main.cpp @@ -53,6 +53,7 @@ void execute(std::string& file,std::string& command) return; } parse.set_toklist(lexer.get_token_list()); + lexer.get_token_list().clear(); parse.main_process(); if(parse.get_error()) { @@ -65,6 +66,7 @@ void execute(std::string& file,std::string& command) return; } import.link(parse.get_root()); + parse.get_root().clear(); if(import.get_error()) { die("import",file); diff --git a/nasal_import.h b/nasal_import.h index f268832..0009ecf 100644 --- a/nasal_import.h +++ b/nasal_import.h @@ -87,18 +87,19 @@ nasal_ast nasal_import::file_import(nasal_ast& node) import_lex.scanner(); if(import_lex.get_error()) { - this->die(filename,"lexer"); + die(filename,"lexer"); return tmp; } import_par.set_toklist(import_lex.get_token_list()); + import_lex.get_token_list().clear(); import_par.main_process(); if(import_par.get_error()) { - this->die(filename,"parser"); + die(filename,"parser"); return tmp; } tmp=import_par.get_root(); - + import_par.get_root().clear(); // check if tmp has 'import' return load(tmp); } diff --git a/nasal_lexer.h b/nasal_lexer.h index 5abefd8..6a90739 100644 --- a/nasal_lexer.h +++ b/nasal_lexer.h @@ -125,7 +125,8 @@ void nasal_lexer::openfile(std::string filename) { ++error; std::cout<<">> [lexer] cannot open file \""<