P_GetNodeType: Do not dereference invalid pointer for **nodedata parameter

This commit is contained in:
toaster 2023-07-20 17:54:47 +01:00
parent a752e6c8e4
commit dee2489620

View file

@ -3205,11 +3205,18 @@ static nodetype_t P_GetNodetype(const virtres_t *virt, UINT8 **nodedata)
nodetype_t nodetype = NT_UNSUPPORTED;
char signature[4 + 1];
*nodedata = NULL;
if (udmf)
{
*nodedata = vres_Find(virt, "ZNODES")->data;
virtlump_t *virtznodes = vres_Find(virt, "ZNODES");
if (virtznodes && virtznodes->size)
{
*nodedata = virtznodes->data;
supported[NT_XGLN] = supported[NT_XGL3] = true;
}
}
else
{
virtlump_t *virtsegs = vres_Find(virt, "SEGS");
@ -3217,10 +3224,15 @@ static nodetype_t P_GetNodetype(const virtres_t *virt, UINT8 **nodedata)
if (virtsegs && virtsegs->size)
{
*nodedata = vres_Find(virt, "NODES")->data;
virtlump_t *virtnodes = vres_Find(virt, "NODES");
if (virtnodes && virtnodes->size)
{
*nodedata = virtnodes->data;
return NT_DOOM; // Traditional map format BSP tree.
}
}
else
{
virtssectors = vres_Find(virt, "SSECTORS");
if (virtssectors && virtssectors->size)
@ -3230,10 +3242,20 @@ static nodetype_t P_GetNodetype(const virtres_t *virt, UINT8 **nodedata)
}
else
{ // Possibly ZDoom extended nodes: SSECTORS is empty, NODES has a signature.
*nodedata = vres_Find(virt, "NODES")->data;
virtlump_t *virtnodes = vres_Find(virt, "NODES");
if (virtnodes && virtnodes->size)
{
*nodedata = virtnodes->data;
supported[NT_XNOD] = supported[NT_ZNOD] = true;
}
}
}
}
if (*nodedata == NULL)
{
I_Error("Level has no nodes (does your map have at least 2 sectors?)");
}
M_Memcpy(signature, *nodedata, 4);
signature[4] = '\0';