aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-26 23:41:15 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-26 23:42:48 +0200
commite869bfd0f66a6107c764d9bd27b14e129e4b404f (patch)
tree8500e00c037594ac94e573f43e9538b567cffdf2 /src
parent4305732e0a09a9e8ae8da6c076c4f65fa0c9c280 (diff)
human_player: deprecate memset(3) for zero-init
Diffstat (limited to 'src')
-rw-r--r--src/player/inc/human_player.h2
-rw-r--r--src/player/src/human_player.c17
2 files changed, 12 insertions, 7 deletions
diff --git a/src/player/inc/human_player.h b/src/player/inc/human_player.h
index fc6dd07..7d28b34 100644
--- a/src/player/inc/human_player.h
+++ b/src/player/inc/human_player.h
@@ -52,7 +52,7 @@ struct human_player
} d;
} sel[MAX_SELECTED_INSTANCES];
- struct
+ struct human_player_target
{
const struct instance *ins;
unsigned char t, n;
diff --git a/src/player/src/human_player.c b/src/player/src/human_player.c
index ffc4fd4..1d2af7d 100644
--- a/src/player/src/human_player.c
+++ b/src/player/src/human_player.c
@@ -430,9 +430,12 @@ static void set_target(struct human_player *const h, struct unit *const u,
const struct unit_target *const t)
{
unit_set_target(u, t);
- memset(&h->target, 0, sizeof h->target);
- h->target.ins = t->ins;
- h->target.render = true;
+
+ h->target = (const struct human_player_target)
+ {
+ .ins = t->ins,
+ .render = true
+ };
}
static void target_from_pos(struct player *const p,
@@ -487,7 +490,9 @@ static void move_units(struct human_player *const h,
static void deselect_instances(struct human_player *const h)
{
- memset(h->sel, 0, sizeof h->sel);
+ for (size_t i = 0; i < sizeof h->sel / sizeof *h->sel; i++)
+ h->sel[i] = (const struct sel_instance){0};
+
h->n_sel = 0;
}
@@ -520,7 +525,7 @@ static void update_target(struct human_player *const h)
enum {TOGGLE = 10};
if (!i->alive)
- memset(&h->target, 0, sizeof h->target);
+ h->target = (const struct human_player_target){0};
else if (++h->target.t >= TOGGLE)
{
enum {TIMES = 5};
@@ -529,7 +534,7 @@ static void update_target(struct human_player *const h)
h->target.t = 0;
if (++h->target.n >= TIMES)
- memset(&h->target, 0, sizeof h->target);
+ h->target = (const struct human_player_target){0};
}
}
}