From 61ee8ca42a5c4e6ddb541304cea471032a48a79a Mon Sep 17 00:00:00 2001 From: Yexo Date: Tue, 20 Jan 2009 15:58:40 +0000 Subject: [PATCH] (svn r15171) -Fix (r15027): Buffer underflow in case there are no settings to save for an AI. --- src/ai/ai_config.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ai/ai_config.cpp b/src/ai/ai_config.cpp index cd0cc8f301..dbae4bce06 100644 --- a/src/ai/ai_config.cpp +++ b/src/ai/ai_config.cpp @@ -208,5 +208,7 @@ void AIConfig::SettingsToString(char *string, int size) strcat(string, no); strcat(string, ","); } - string[strlen(string) - 1] = '\0'; + /* Remove the last ',', but only if at least one setting was saved. */ + size_t len = strlen(string); + if (len > 0) string[len - 1] = '\0'; }