From cbe7ca6fcadc28c331a4df0aa6c6d2dea8db8c4e Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sun, 26 Jun 2022 19:58:46 +0200 Subject: player: limit data sizes for resources and population - All platforms should allow for the same resources. - Population is not expected to exceed UCHAR_MAX on any platform. --- src/player/inc/human_player.h | 3 ++- src/player/inc/player.h | 4 ++-- src/player/src/human_player.c | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/player/inc/human_player.h b/src/player/inc/human_player.h index 39a0d6d..fc6dd07 100644 --- a/src/player/inc/human_player.h +++ b/src/player/inc/human_player.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #ifdef __cplusplus @@ -60,7 +61,7 @@ struct human_player size_t n_sel; bool top_gui; - unsigned long gui_res[MAX_RESOURCE_TYPES]; + uint32_t gui_res[MAX_RESOURCE_TYPES]; }; int human_player_init(const struct human_player_cfg *cfg, struct human_player *h); diff --git a/src/player/inc/player.h b/src/player/inc/player.h index 25f4d81..153740c 100644 --- a/src/player/inc/player.h +++ b/src/player/inc/player.h @@ -36,8 +36,8 @@ struct player bool alive; struct unit units[PLAYER_MAX_UNITS]; struct building buildings[PLAYER_MAX_BUILDINGS]; - unsigned long resources[MAX_RESOURCE_TYPES]; - size_t pop, bpop; + uint32_t resources[MAX_RESOURCE_TYPES]; + unsigned char pop, bpop; struct { diff --git a/src/player/src/human_player.c b/src/player/src/human_player.c index a70eddf..aea587c 100644 --- a/src/player/src/human_player.c +++ b/src/player/src/human_player.c @@ -726,6 +726,8 @@ int human_player_init(const struct human_player_cfg *const cfg, cursor_init(&h->cam.cursor); h->cam.dim = cfg->dim; h->top_gui = true; + UTIL_STATIC_ASSERT(sizeof h->gui_res == sizeof h->pl.resources, + "unexpected sizeof for h->gui_res"); memmove(h->gui_res, h->pl.resources, sizeof h->gui_res); return 0; } -- cgit v1.2.3