[Freeciv-Dev] Re: (PR#9310) startunits
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9310 >
Marko Lindqvist wrote:
>> Attached patch takes care of the most critical part of this ticket;
>>savegame loading was not checking array bounds when loading old saves,
>>so loading such an old game with > 15 startunits got out of bounds.
>
> This version also increases limit to 20 units. Turned out that not
> even network compatibility nor old clients break.
Lets fit that terminating '\0' within array bounds too...
- Caz
diff -Nurd -X.diff_ignore freeciv/common/game.h freeciv/common/game.h
--- freeciv/common/game.h 2004-09-26 11:51:08.968750000 +0300
+++ freeciv/common/game.h 2004-09-26 18:40:03.218750000 +0300
@@ -31,7 +31,7 @@
#define MAX_LEN_ALLOW_TAKE 16
#define MAX_ID_LEN 33
#define MAX_GRANARY_INIS 24
-#define MAX_LEN_STARTUNIT 16
+#define MAX_LEN_STARTUNIT (20+1)
enum server_states {
PRE_GAME_STATE,
diff -Nurd -X.diff_ignore freeciv/server/savegame.c freeciv/server/savegame.c
--- freeciv/server/savegame.c 2004-09-26 11:51:45.843750000 +0300
+++ freeciv/server/savegame.c 2004-09-26 18:40:46.546875000 +0300
@@ -3102,10 +3102,10 @@
int settlers = secfile_lookup_int(file, "game.settlers");
int explorer = secfile_lookup_int(file, "game.explorer");
int i;
- for (i = 0; settlers>0; i++, settlers--) {
+ for (i = 0; settlers > 0 && i < (MAX_LEN_STARTUNIT - 1) ; i++,
settlers--) {
game.start_units[i] = 'c';
}
- for (; explorer>0; i++, explorer--) {
+ for (; explorer > 0 && i < (MAX_LEN_STARTUNIT - 1) ; i++, explorer--)
{
game.start_units[i] = 'x';
}
game.start_units[i] = '\0';
|
|