Check if pSoldier is null

Prevent nullptr dereference in AI logging function
This commit is contained in:
Asdow
2024-01-28 11:16:41 +02:00
parent 5a74323d1f
commit 2697a17010
+2 -8
View File
@@ -217,7 +217,7 @@ void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction )
CHAR8 msg[1024];
CHAR8 buf[1024];
if (!gfLogsEnabled)
if (!gfLogsEnabled || pSoldier == nullptr)
return;
memset(buf, 0, 1024 * sizeof(char));
@@ -235,8 +235,6 @@ void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction )
sprintf(msg, "");
if (pSoldier)
{
sprintf(buf, "[%d] (%d)", pSoldier->ubID, pSoldier->sGridNo);
strcat(msg, buf);
@@ -246,7 +244,6 @@ void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction )
strcat(msg, " ");
strcat(msg, buf);
}
}
strcat(msg, " ");
@@ -266,13 +263,10 @@ void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction )
strcat(msg, " ");
strcat(msg, szAction[bAction]);
if (pSoldier)
{
sprintf(buf, " %d", pSoldier->aiData.usActionData);
strcat(msg, buf);
}
if (pSoldier && pSoldier->aiData.bNextAction != AI_ACTION_NONE)
if (pSoldier->aiData.bNextAction != AI_ACTION_NONE)
{
strcat(msg, " ");
strcat(msg, szAction[pSoldier->aiData.bNextAction]);