* fixed memory allocation crash when using ?{fread,file ALL} in scripts

* found a bug with causes block mismatches in def scripts with multiple nested if/loop/endif/endloop blocks. not yet fixed, but added small check.
This commit is contained in:
false_genesis 2008-01-23 22:13:05 +00:00
parent 1d12dbed90
commit 94c4994a12
2 changed files with 16 additions and 2 deletions

View File

@ -375,6 +375,11 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
}
else if(line=="loop")
Blocks.push_back(BLOCK_LOOP);
else if(line=="exitloop" && !Blocks.size()) // TODO: check: at least one BLOCK_LOOP must be opened
{
cantload=true;
break;
}
else if(line=="endloop")
{
if(Blocks.empty() || Blocks.back()!=BLOCK_LOOP)

View File

@ -113,13 +113,22 @@ DefReturnResult DefScriptPackage::func_fwrite(CmdSet& Set)
DefReturnResult DefScriptPackage::func_fread(CmdSet& Set)
{
std::fstream *fh = files.GetNoCreate(_NormalizeVarName(Set.arg[0],Set.myname));
std::string fn = _NormalizeVarName(Set.arg[0],Set.myname);
std::fstream *fh = files.GetNoCreate(fn);
if(fh && fh->is_open())
{
uint64 bytes;
uint64 read = 0;
if(stringToLower(Set.defaultarg) == "all")
bytes = -1LL;
{
std::fstream::pos_type begin_pos, end_pos, old_pos = fh->tellg();
fh->seekg(0, std::ios_base::beg);
begin_pos=fh->tellg();
fh->seekg(0, std::ios_base::end);
end_pos = fh->tellg();
fh->seekg(old_pos, std::ios_base::beg);
bytes = (end_pos - begin_pos);
}
else
bytes = toUint64(Set.defaultarg);
std::string ret;