main: guard against rnd(0) in rndmapname

starting ac_client from the wrong working directory, where
packages/maps/official/*.cgz globs to an empty list, we
trigger a SIGFPE because of rnd(0):

Program received signal SIGFPE, Arithmetic exception.
0x000000000044d37d in rndmapname () at main.cpp:897
897	        char *map = newstring(maps[rnd(maps.length())]);
This commit is contained in:
Pascal de Bruijn
2014-03-27 18:20:21 +01:00
committed by Pascal de Bruijn
parent 3fd1004383
commit 7482f259cf
+7 -3
View File
@@ -895,9 +895,13 @@ const char *rndmapname()
{
vector<char *> maps;
listfiles("packages/maps/official", "cgz", maps);
char *map = newstring(maps[rnd(maps.length())]);
maps.deletearrays();
return map;
if (maps.length() > 0)
{
char *map = newstring(maps[rnd(maps.length())]);
maps.deletearrays();
return map;
}
else return "";
}
extern void connectserv(char *, int *, char *);