From fbda0468c6c74e97e81e5c5702a0fac4ec1ae8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 17 Oct 2021 22:50:59 +0200 Subject: [PATCH] fix exception in GetAnnouncementLine with empty list --- src/engine/server/server.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index e5136eae6..9f5643837 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -3667,7 +3667,12 @@ const char *CServer::GetAnnouncementLine(char const *pFileName) if(str_length(pLine)) if(pLine[0] != '#') Lines.push_back(pLine); - if(Lines.size() == 1) + + if(Lines.empty()) + { + return 0; + } + else if(Lines.size() == 1) { m_AnnouncementLastLine = 0; } @@ -3680,8 +3685,9 @@ const char *CServer::GetAnnouncementLine(char const *pFileName) { unsigned Rand; do + { Rand = rand() % Lines.size(); - while(Rand == m_AnnouncementLastLine); + } while(Rand == m_AnnouncementLastLine); m_AnnouncementLastLine = Rand; }