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

This commit is contained in:
toaster 2023-07-15 19:18:39 +01:00
parent ed8007471f
commit 459e3684ab

View file

@ -3572,10 +3572,17 @@ static nodetype_t P_GetNodetype(const virtres_t *virt, UINT8 **nodedata)
nodetype_t nodetype = NT_UNSUPPORTED; nodetype_t nodetype = NT_UNSUPPORTED;
char signature[4 + 1]; char signature[4 + 1];
*nodedata = NULL;
if (udmf) if (udmf)
{ {
*nodedata = vres_Find(virt, "ZNODES")->data; virtlump_t *virtznodes = vres_Find(virt, "ZNODES");
supported[NT_XGLN] = supported[NT_XGL3] = true;
if (virtznodes && virtznodes->size)
{
*nodedata = virtznodes->data;
supported[NT_XGLN] = supported[NT_XGL3] = true;
}
} }
else else
{ {
@ -3584,24 +3591,39 @@ static nodetype_t P_GetNodetype(const virtres_t *virt, UINT8 **nodedata)
if (virtsegs && virtsegs->size) if (virtsegs && virtsegs->size)
{ {
*nodedata = vres_Find(virt, "NODES")->data; virtlump_t *virtnodes = vres_Find(virt, "NODES");
return NT_DOOM; // Traditional map format BSP tree. if (virtnodes && virtnodes->size)
} {
*nodedata = virtnodes->data;
virtssectors = vres_Find(virt, "SSECTORS"); return NT_DOOM; // Traditional map format BSP tree.
}
if (virtssectors && virtssectors->size)
{ // Possibly GL nodes: NODES ignored, SSECTORS takes precedence as nodes lump, (It is confusing yeah) and has a signature.
*nodedata = virtssectors->data;
supported[NT_XGLN] = supported[NT_ZGLN] = supported[NT_XGL3] = true;
} }
else else
{ // Possibly ZDoom extended nodes: SSECTORS is empty, NODES has a signature. {
*nodedata = vres_Find(virt, "NODES")->data; virtssectors = vres_Find(virt, "SSECTORS");
supported[NT_XNOD] = supported[NT_ZNOD] = true;
if (virtssectors && virtssectors->size)
{ // Possibly GL nodes: NODES ignored, SSECTORS takes precedence as nodes lump, (It is confusing yeah) and has a signature.
*nodedata = virtssectors->data;
supported[NT_XGLN] = supported[NT_ZGLN] = supported[NT_XGL3] = true;
}
else
{ // Possibly ZDoom extended nodes: SSECTORS is empty, NODES has a signature.
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); M_Memcpy(signature, *nodedata, 4);
signature[4] = '\0'; signature[4] = '\0';
(*nodedata) += 4; (*nodedata) += 4;