(svn r24982) -Fix [FS#5465]: [Script] Crash when passing too many parameters

This commit is contained in:
rubidium
2013-02-08 20:34:27 +00:00
parent bb225ae39e
commit 4e61c1770d
13 changed files with 151 additions and 121 deletions

View File

@@ -165,25 +165,28 @@ SQInteger ScriptText::_set(HSQUIRRELVM vm)
const char *ScriptText::GetEncodedText()
{
static char buf[1024];
this->_GetEncodedText(buf, lastof(buf));
return buf;
int param_count = 0;
this->_GetEncodedText(buf, lastof(buf), param_count);
return (param_count > SCRIPT_TEXT_MAX_PARAMETERS) ? NULL : buf;
}
char *ScriptText::_GetEncodedText(char *p, char *lastofp)
char *ScriptText::_GetEncodedText(char *p, char *lastofp, int &param_count)
{
p += Utf8Encode(p, SCC_ENCODED);
p += seprintf(p, lastofp, "%X", this->string);
for (int i = 0; i < this->paramc; i++) {
if (this->params[i] != NULL) {
p += seprintf(p, lastofp, ":\"%s\"", this->params[i]);
param_count++;
continue;
}
if (this->paramt[i] != NULL) {
p += seprintf(p, lastofp, ":");
p = this->paramt[i]->_GetEncodedText(p, lastofp);
p = this->paramt[i]->_GetEncodedText(p, lastofp, param_count);
continue;
}
p += seprintf(p, lastofp,":%X", (uint32)this->parami[i]);
param_count++;
}
return p;