aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-26 19:58:46 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-26 19:58:46 +0200
commiteee1205446e3b1832b256dfebac66f0a0f42e528 (patch)
treef9cb467009dba936d0c6674fa9329fec978910e4
parent9da37c198e88ebade4a176bc1d7c9a9ebd388862 (diff)
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.
-rw-r--r--src/player/inc/human_player.h3
-rw-r--r--src/player/inc/player.h4
-rw-r--r--src/player/src/human_player.c2
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 <peripheral.h>
#include <player.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stddef.h>
#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;
}