mirror of
https://github.com/1dot13/source.git
synced 2026-09-09 14:46:05 +02:00
Check if pSoldier is null
Prevent nullptr dereference in AI logging function
This commit is contained in:
+11
-17
@@ -217,7 +217,7 @@ void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction )
|
|||||||
CHAR8 msg[1024];
|
CHAR8 msg[1024];
|
||||||
CHAR8 buf[1024];
|
CHAR8 buf[1024];
|
||||||
|
|
||||||
if (!gfLogsEnabled)
|
if (!gfLogsEnabled || pSoldier == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memset(buf, 0, 1024 * sizeof(char));
|
memset(buf, 0, 1024 * sizeof(char));
|
||||||
@@ -235,17 +235,14 @@ void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction )
|
|||||||
|
|
||||||
sprintf(msg, "");
|
sprintf(msg, "");
|
||||||
|
|
||||||
if (pSoldier)
|
sprintf(buf, "[%d] (%d)", pSoldier->ubID, pSoldier->sGridNo);
|
||||||
{
|
strcat(msg, buf);
|
||||||
sprintf(buf, "[%d] (%d)", pSoldier->ubID, pSoldier->sGridNo);
|
|
||||||
strcat(msg, buf);
|
|
||||||
|
|
||||||
if (pSoldier->ubProfile != NO_PROFILE)
|
if (pSoldier->ubProfile != NO_PROFILE)
|
||||||
{
|
{
|
||||||
wcstombs(buf, pSoldier->GetName(), 1024 - 1);
|
wcstombs(buf, pSoldier->GetName(), 1024 - 1);
|
||||||
strcat(msg, " ");
|
strcat(msg, " ");
|
||||||
strcat(msg, buf);
|
strcat(msg, buf);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strcat(msg, " ");
|
strcat(msg, " ");
|
||||||
@@ -266,13 +263,10 @@ void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction )
|
|||||||
strcat(msg, " ");
|
strcat(msg, " ");
|
||||||
strcat(msg, szAction[bAction]);
|
strcat(msg, szAction[bAction]);
|
||||||
|
|
||||||
if (pSoldier)
|
sprintf(buf, " %d", pSoldier->aiData.usActionData);
|
||||||
{
|
strcat(msg, buf);
|
||||||
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, " ");
|
||||||
strcat(msg, szAction[pSoldier->aiData.bNextAction]);
|
strcat(msg, szAction[pSoldier->aiData.bNextAction]);
|
||||||
|
|||||||
Reference in New Issue
Block a user