mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-26 18:40:54 +00:00
Fix #138 Pointer truncation in AI Script VM
This commit is contained in:
parent
affdb36a73
commit
66a9a23ca8
1 changed files with 26 additions and 15 deletions
|
@ -138,7 +138,12 @@ public:
|
||||||
float& getFloat();
|
float& getFloat();
|
||||||
float const& getFloat() const;
|
float const& getFloat() const;
|
||||||
|
|
||||||
int _val;
|
union
|
||||||
|
{
|
||||||
|
int _vali;
|
||||||
|
uintptr_t _valp;
|
||||||
|
};
|
||||||
|
|
||||||
TStackTypes _type;
|
TStackTypes _type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -346,7 +351,7 @@ inline
|
||||||
CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(float const& f)
|
CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(float const& f)
|
||||||
{
|
{
|
||||||
clean();
|
clean();
|
||||||
_val = *((int*)&f);
|
_vali = *((int*)&f);
|
||||||
_type = EFloat;
|
_type = EFloat;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -354,7 +359,7 @@ inline
|
||||||
CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(int const& i)
|
CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(int const& i)
|
||||||
{
|
{
|
||||||
clean();
|
clean();
|
||||||
_val = i;
|
_vali = i;
|
||||||
_type = EOther;
|
_type = EOther;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -363,7 +368,7 @@ CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(std::string cons
|
||||||
{
|
{
|
||||||
clean();
|
clean();
|
||||||
std::string* const strPt = new std::string(str);
|
std::string* const strPt = new std::string(str);
|
||||||
_val = *((int*)&strPt);
|
_valp = *((int*)&strPt);
|
||||||
_type = EString;
|
_type = EString;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -371,7 +376,7 @@ inline
|
||||||
CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(IScriptContext* sc)
|
CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(IScriptContext* sc)
|
||||||
{
|
{
|
||||||
clean();
|
clean();
|
||||||
_val = *((int*)&sc);
|
_valp = *((int*)&sc);
|
||||||
_type = EContext;
|
_type = EContext;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -386,9 +391,11 @@ bool CScriptStack::CStackEntry::operator==(CStackEntry const& other) const
|
||||||
return getString()==other.getString();
|
return getString()==other.getString();
|
||||||
case EFloat:
|
case EFloat:
|
||||||
return getFloat()==other.getFloat();
|
return getFloat()==other.getFloat();
|
||||||
|
case EContext:
|
||||||
|
return _valp==other._valp;
|
||||||
case EOther:
|
case EOther:
|
||||||
default:
|
default:
|
||||||
return _val==other._val;
|
return _vali==other._vali;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,9 +427,11 @@ bool CScriptStack::CStackEntry::operator<(CStackEntry const& other) const
|
||||||
return getString()<other.getString();
|
return getString()<other.getString();
|
||||||
case EFloat:
|
case EFloat:
|
||||||
return getFloat()<other.getFloat();
|
return getFloat()<other.getFloat();
|
||||||
|
case EContext:
|
||||||
|
return _valp<other._valp;
|
||||||
case EOther:
|
case EOther:
|
||||||
default:
|
default:
|
||||||
return _val<other._val;
|
return _vali<other._vali;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,9 +445,11 @@ bool CScriptStack::CStackEntry::operator>(CStackEntry const& other) const
|
||||||
return getString()>other.getString();
|
return getString()>other.getString();
|
||||||
case EFloat:
|
case EFloat:
|
||||||
return getFloat()>other.getFloat();
|
return getFloat()>other.getFloat();
|
||||||
|
case EContext:
|
||||||
|
return _valp>other._valp;
|
||||||
case EOther:
|
case EOther:
|
||||||
default:
|
default:
|
||||||
return _val>other._val;
|
return _vali>other._vali;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,43 +484,43 @@ inline
|
||||||
std::string& CScriptStack::CStackEntry::getString()
|
std::string& CScriptStack::CStackEntry::getString()
|
||||||
{
|
{
|
||||||
nlassert(_type==EString);
|
nlassert(_type==EString);
|
||||||
return *(*((std::string**)&_val));
|
return *(*((std::string**)&_valp));
|
||||||
}
|
}
|
||||||
inline
|
inline
|
||||||
std::string const& CScriptStack::CStackEntry::getString() const
|
std::string const& CScriptStack::CStackEntry::getString() const
|
||||||
{
|
{
|
||||||
nlassert(_type==EString);
|
nlassert(_type==EString);
|
||||||
return *(*((std::string**)&_val));
|
return *(*((std::string**)&_valp));
|
||||||
}
|
}
|
||||||
inline
|
inline
|
||||||
IScriptContext* CScriptStack::CStackEntry::getIScriptContext()
|
IScriptContext* CScriptStack::CStackEntry::getIScriptContext()
|
||||||
{
|
{
|
||||||
nlassert(_type==EContext);
|
nlassert(_type==EContext);
|
||||||
return *((IScriptContext**)&_val);
|
return *((IScriptContext**)&_valp);
|
||||||
}
|
}
|
||||||
inline
|
inline
|
||||||
int& CScriptStack::CStackEntry::getInt()
|
int& CScriptStack::CStackEntry::getInt()
|
||||||
{
|
{
|
||||||
nlassert(_type==EOther);
|
nlassert(_type==EOther);
|
||||||
return _val;
|
return _vali;
|
||||||
}
|
}
|
||||||
inline
|
inline
|
||||||
int const& CScriptStack::CStackEntry::getInt() const
|
int const& CScriptStack::CStackEntry::getInt() const
|
||||||
{
|
{
|
||||||
nlassert(_type==EOther);
|
nlassert(_type==EOther);
|
||||||
return _val;
|
return _vali;
|
||||||
}
|
}
|
||||||
inline
|
inline
|
||||||
float& CScriptStack::CStackEntry::getFloat()
|
float& CScriptStack::CStackEntry::getFloat()
|
||||||
{
|
{
|
||||||
nlassert(_type==EFloat);
|
nlassert(_type==EFloat);
|
||||||
return *((float*)&_val);
|
return *((float*)&_vali);
|
||||||
}
|
}
|
||||||
inline
|
inline
|
||||||
float const& CScriptStack::CStackEntry::getFloat() const
|
float const& CScriptStack::CStackEntry::getFloat() const
|
||||||
{
|
{
|
||||||
nlassert(_type==EFloat);
|
nlassert(_type==EFloat);
|
||||||
return *((float const*)&_val);
|
return *((float const*)&_vali);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
|
|
Loading…
Reference in a new issue