I accidentally attempted to use an Autohandle for a type before registering that type. The result is that in the following code dt.GetObjectType() returns 0. Accessing 0->flags produces an access violation.
as_builder.cpp: line 4619
if( n && n->tokenType == ttPlus )
{
// Autohandles are not supported for types with NOCOUNT
if( dt.GetObjectType()->flags & asOBJ_NOCOUNT )
WriteError(TXT_AUTOHANDLE_CANNOT_BE_USED_FOR_NOCOUNT, file, node->firstChild);
if( autoHandle ) *autoHandle = true;
}
This is because the following call to CreateDataTypeFromNode failed to find a type for the unregistered handle, and it returned [ttInt]
as_builder.cpp: line 962
// Scoped reference types are allowed to use handle when returned from application functions
func->returnType = CreateDataTypeFromNode(node->firstChild, &source, objType ? objType->nameSpace : ns, true, objType);
func->returnType = ModifyDataTypeFromNode(func->returnType, node->firstChild->next, &source, 0, &autoHandle);
if( autoHandle && (!func->returnType.IsObjectHandle() || func->returnType.IsReference()) )
return asINVALID_DECLARATION;
To correct the error, I was able to either test for an error condition earlier:
// Scoped reference types are allowed to use handle when returned from application functions
func->returnType = CreateDataTypeFromNode(node->firstChild, &source, objType ? objType->nameSpace : ns, true, objType);
if( numErrors > 0 || numWarnings > 0 )
return asINVALID_DECLARATION;
func->returnType = ModifyDataTypeFromNode(func->returnType, node->firstChild->next, &source, 0, &autoHandle);
if( autoHandle && (!func->returnType.IsObjectHandle() || func->returnType.IsReference()) )
return asINVALID_DECLARATION;
Or test for a null asCObjectType*:
if( n && n->tokenType == ttPlus )
{
asCObjectType *ot = dt.GetObjectType();
// Autohandles are not supported for primitive types
if( ot == nullptr )
WriteError("Autohandles are not supported for primitive types.", file, node->firstChild);
// Autohandles are not supported for types with NOCOUNT
else if( dt.GetObjectType()->flags & asOBJ_NOCOUNT )
WriteError(TXT_AUTOHANDLE_CANNOT_BE_USED_FOR_NOCOUNT, file, node->firstChild);
if( autoHandle ) *autoHandle = true;
}