bug fixed

fixed SIGSEGV when failed to load file in nasal_lexer::openfile
This commit is contained in:
Valk Richard Li 2021-06-06 19:17:02 +08:00
parent b25a1bc3f4
commit 9f2c31149a
3 changed files with 9 additions and 4 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -126,6 +126,7 @@ void nasal_lexer::openfile(std::string filename)
++error;
std::cout<<">> [lexer] cannot open file \""<<filename<<"\".\n";
fin.close();
res_size=0;
return;
}
while(!fin.eof())
@ -390,6 +391,7 @@ void nasal_lexer::scanner()
}
token tk(line,tok_eof,"");
token_list.push_back(tk);
res.clear();
return;
}