fix exception in GetAnnouncementLine with empty list

This commit is contained in:
Robert Müller 2021-10-17 22:50:59 +02:00
parent 8ffc7967f8
commit fbda0468c6

View file

@ -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;
}