AngelScript 2.29.0.
Add-on: scriptarray.cpp.
For default allocator used asAllocMem, which is not zeroing memory.
And after resizing array with pod types we have uninitialized data in array.
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
AngelScript 2.29.0.
Add-on: scriptarray.cpp.
For default allocator used asAllocMem, which is not zeroing memory.
And after resizing array with pod types we have uninitialized data in array.
I think better rework Construct method from this:
void CScriptArray::Construct(SArrayBuffer *buf, asUINT start, asUINT end)
{
if( subTypeId & asTYPEID_OBJHANDLE )
{
// Set all object handles to null
void *d = (void*)(buf->data + start * sizeof(void*));
memset(d, 0, (end-start)*sizeof(void*));
}
else if( subTypeId & asTYPEID_MASK_OBJECT )
{
void **max = (void**)(buf->data + end * sizeof(void*));
void **d = (void**)(buf->data + start * sizeof(void*));
asIScriptEngine *engine = objType->GetEngine();
asIObjectType *subType = objType->GetSubType();
for( ; d < max; d++ )
{
*d = (void*)engine->CreateScriptObject(subType);
if( *d == 0 )
{
// Set the remaining entries to null so the destructor
// won't attempt to destroy invalid objects later
memset(d, 0, sizeof(void*)*(max-d));
// There is no need to set an exception on the context,
// as CreateScriptObject has already done that
return;
}
}
}
}
to this:
void CScriptArray::Construct(SArrayBuffer *buf, asUINT start, asUINT end)
{
if( subTypeId & asTYPEID_MASK_OBJECT )
{
void **max = (void**)(buf->data + end * sizeof(void*));
void **d = (void**)(buf->data + start * sizeof(void*));
asIScriptEngine *engine = objType->GetEngine();
asIObjectType *subType = objType->GetSubType();
for( ; d < max; d++ )
{
*d = (void*)engine->CreateScriptObject(subType);
if( *d == 0 )
{
// Set the remaining entries to null so the destructor
// won't attempt to destroy invalid objects later
memset(d, 0, sizeof(void*)*(max-d));
// There is no need to set an exception on the context,
// as CreateScriptObject has already done that
return;
}
}
}
else
{
// Set all to zero
void *d = (void*)(buf->data + start * sizeof(void*));
memset(d, 0, (end-start)*sizeof(void*));
}
}