mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 03:33:48 +00:00
Fix corruption issue with string iterator was using an absolute pointer. Also adds a special relative pointer type for constructed strings on the stack.
This commit is contained in:
parent
97ab694af8
commit
942c7a48f4
7 changed files with 151 additions and 29 deletions
|
|
@ -512,7 +512,7 @@ void ConsoleValue::setStringValue(const char * value)
|
|||
*/
|
||||
if (value == typeValueEmpty)
|
||||
{
|
||||
if (sval && sval != typeValueEmpty && type != TypeInternalStackString) dFree(sval);
|
||||
if (sval && sval != typeValueEmpty && type != TypeInternalStackString && type != TypeInternalStringStackPtr) dFree(sval);
|
||||
sval = typeValueEmpty;
|
||||
bufferLen = 0;
|
||||
fval = 0.f;
|
||||
|
|
@ -541,7 +541,7 @@ void ConsoleValue::setStringValue(const char * value)
|
|||
// may as well pad to the next cache line
|
||||
U32 newLen = ((stringLen + 1) + 15) & ~15;
|
||||
|
||||
if(sval == typeValueEmpty || type == TypeInternalStackString)
|
||||
if(sval == typeValueEmpty || type == TypeInternalStackString || type == TypeInternalStringStackPtr)
|
||||
sval = (char *) dMalloc(newLen);
|
||||
else if(newLen > bufferLen)
|
||||
sval = (char *) dRealloc(sval, newLen);
|
||||
|
|
@ -556,7 +556,7 @@ void ConsoleValue::setStringValue(const char * value)
|
|||
}
|
||||
|
||||
|
||||
void ConsoleValue::setStackStringValue(const char * value)
|
||||
void ConsoleValue::setStackStringValue(const char *value)
|
||||
{
|
||||
if (value == NULL) value = typeValueEmpty;
|
||||
|
||||
|
|
@ -564,7 +564,7 @@ void ConsoleValue::setStackStringValue(const char * value)
|
|||
{
|
||||
if (value == typeValueEmpty)
|
||||
{
|
||||
if (sval && sval != typeValueEmpty && type != ConsoleValue::TypeInternalStackString) dFree(sval);
|
||||
if (sval && sval != typeValueEmpty && type != ConsoleValue::TypeInternalStackString && type != ConsoleValue::TypeInternalStringStackPtr) dFree(sval);
|
||||
sval = typeValueEmpty;
|
||||
bufferLen = 0;
|
||||
fval = 0.f;
|
||||
|
|
@ -586,13 +586,42 @@ void ConsoleValue::setStackStringValue(const char * value)
|
|||
}
|
||||
|
||||
type = TypeInternalStackString;
|
||||
sval = (char*)value;
|
||||
sval = (char*)value;
|
||||
bufferLen = stringLen;
|
||||
}
|
||||
else
|
||||
Con::setData(type, dataPtr, 0, 1, &value, enumTable);
|
||||
}
|
||||
|
||||
void ConsoleValue::setStringStackPtrValue(StringStackPtr ptrValue)
|
||||
{
|
||||
if(type <= ConsoleValue::TypeInternalString)
|
||||
{
|
||||
const char *value = StringStackPtrRef(ptrValue).getPtr(&STR);
|
||||
if (sval && sval != typeValueEmpty && type != ConsoleValue::TypeInternalStackString && type != TypeInternalStringStackPtr) dFree(sval);
|
||||
|
||||
U32 stringLen = dStrlen(value);
|
||||
if(stringLen < 256)
|
||||
{
|
||||
fval = dAtof(value);
|
||||
ival = dAtoi(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
fval = 0.f;
|
||||
ival = 0;
|
||||
}
|
||||
|
||||
type = TypeInternalStringStackPtr;
|
||||
sval = (char*)(value - STR.mBuffer);
|
||||
bufferLen = stringLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *value = StringStackPtrRef(ptrValue).getPtr(&STR);
|
||||
Con::setData(type, dataPtr, 0, 1, &value, enumTable);
|
||||
}
|
||||
}
|
||||
|
||||
S32 Dictionary::getIntVariable(StringTableEntry name, bool *entValid)
|
||||
{
|
||||
|
|
@ -651,7 +680,8 @@ Dictionary::Entry* Dictionary::addVariable( const char *name,
|
|||
Entry *ent = add(StringTable->insert(name));
|
||||
|
||||
if ( ent->value.type <= ConsoleValue::TypeInternalString &&
|
||||
ent->value.sval != typeValueEmpty && ent->value.type != ConsoleValue::TypeInternalStackString )
|
||||
ent->value.sval != typeValueEmpty &&
|
||||
ent->value.type != ConsoleValue::TypeInternalStackString && ent->value.type != ConsoleValue::TypeInternalStringStackPtr )
|
||||
dFree(ent->value.sval);
|
||||
|
||||
ent->value.type = type;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue