From ada1dbf5853339ba1ba35581bd3aa37cb52185f3 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 28 Jan 2024 11:07:25 +0200 Subject: [PATCH 1/2] Disable AI logging by default We only want this on when specifically debugging/working on AI. --- TacticalAI/AIMain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TacticalAI/AIMain.cpp b/TacticalAI/AIMain.cpp index 0aab1c326..a19a1e771 100644 --- a/TacticalAI/AIMain.cpp +++ b/TacticalAI/AIMain.cpp @@ -209,7 +209,7 @@ STR szAction[] = { // sevenfm UINT32 guiAIStartCounter = 0, guiAILastCounter = 0; //UINT8 gubAISelectedSoldier = NOBODY; -BOOLEAN gfLogsEnabled = TRUE; +BOOLEAN gfLogsEnabled = FALSE; void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction ) { From 37b0200ac9c35bfda7da33d59481e86bcd9035a2 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 28 Jan 2024 11:08:06 +0200 Subject: [PATCH 2/2] Check if pSoldier is null Prevent nullptr dereference in AI logging function --- TacticalAI/AIMain.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/TacticalAI/AIMain.cpp b/TacticalAI/AIMain.cpp index a19a1e771..f4d0d4316 100644 --- a/TacticalAI/AIMain.cpp +++ b/TacticalAI/AIMain.cpp @@ -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,17 +235,14 @@ 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); + + if (pSoldier->ubProfile != NO_PROFILE) { - sprintf(buf, "[%d] (%d)", pSoldier->ubID, pSoldier->sGridNo); + wcstombs(buf, pSoldier->GetName(), 1024 - 1); + strcat(msg, " "); strcat(msg, buf); - - if (pSoldier->ubProfile != NO_PROFILE) - { - wcstombs(buf, pSoldier->GetName(), 1024 - 1); - 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); - } + 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]);