Skip to content

Commit 827cc1f

Browse files
committed
src: replace most memsets with initializers
1 parent 25d9ba0 commit 827cc1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+148
-153
lines changed

src/aniplayer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
#include "stageobjects.h"
1313

1414
void aniplayer_create(AniPlayer *plr, Animation *ani, const char *startsequence) {
15-
memset(plr,0,sizeof(AniPlayer));
16-
plr->ani = ani;
15+
*plr = (typeof(*plr)) {
16+
.ani = ani,
17+
};
1718

1819
aniplayer_queue(plr,startsequence,0);
1920
}

src/audio/stream/mixer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ bool mixer_group_get_channels_range(AudioChannelGroup group, int *first, int *la
8787
// BEGIN INIT/SHUTDOWN
8888

8989
bool mixer_init(Mixer *mx, const AudioStreamSpec *spec) {
90-
memset(mx, 0, sizeof(*mx));
90+
*mx = (typeof(*mx)) {};
9191

9292
if(!splayer_init(mx->players + CHANGROUP_BGM, MIXER_NUM_BGM_CHANNELS, spec)) {
9393
log_error("splayer_init() failed");
@@ -118,7 +118,7 @@ void mixer_shutdown(Mixer *mx) {
118118

119119
if(plr->channels) {
120120
splayer_shutdown(plr);
121-
memset(plr, 0, sizeof(*plr));
121+
*plr = (typeof(*plr)) {};
122122
}
123123
}
124124
}

src/audio/stream/player.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ union audio_buffer {
2525
};
2626

2727
bool splayer_init(StreamPlayer *plr, int num_channels, const AudioStreamSpec *dst_spec) {
28-
memset(plr, 0, sizeof(*plr));
28+
*plr = (typeof(*plr)) {};
2929

3030
if(dst_spec->sample_format != SDL_AUDIO_F32) {
3131
log_error("Unsupported audio format: 0x%4x", dst_spec->sample_format);

src/boss.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,15 +1427,15 @@ void boss_start_next_attack(Boss *b, Attack *a) {
14271427
Attack *boss_add_attack(Boss *boss, AttackType type, const char *name, float timeout, int hp, BossRule draw_rule) {
14281428
assert(boss->acount < BOSS_MAX_ATTACKS);
14291429

1430-
Attack *a = &boss->attacks[boss->acount];
1431-
boss->acount += 1;
1432-
memset(a, 0, sizeof(Attack));
1433-
a->type = type;
1434-
a->name = name;
1435-
a->timeout = timeout * FPS;
1436-
a->maxhp = hp;
1437-
a->hp = hp;
1438-
a->draw_rule = draw_rule;
1430+
Attack *a = &boss->attacks[boss->acount++];
1431+
*a = (typeof(*a)) {
1432+
.type = type,
1433+
.name = name,
1434+
.timeout = timeout * FPS,
1435+
.maxhp = hp,
1436+
.hp = hp,
1437+
.draw_rule = draw_rule,
1438+
};
14391439

14401440
COEVENT_INIT_ARRAY(a->events);
14411441

src/cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int cli_args(int argc, char **argv, CLIAction *a) {
104104
{}
105105
};
106106

107-
memset(a, 0, sizeof(*a));
107+
*a = (typeof(*a)) {};
108108

109109
int nopts = ARRAY_SIZE(taisei_opts);
110110
struct option opts[nopts];

src/coroutine/cosched.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "hashtable.h"
1313

1414
void cosched_init(CoSched *sched) {
15-
memset(sched, 0, sizeof(*sched));
15+
*sched = (typeof(*sched)) {};
1616
}
1717

1818
CoTask *_cosched_new_task(CoSched *sched, CoTaskFunc func, void *arg, size_t arg_size, bool is_subtask, CoTaskDebugInfo debug) {
@@ -136,5 +136,5 @@ void cosched_finish(CoSched *sched) {
136136
finish_task_list(&sched->pending_tasks);
137137
assert(!sched->tasks.first);
138138
assert(!sched->pending_tasks.first);
139-
memset(sched, 0, sizeof(*sched));
139+
*sched = (typeof(*sched)) {};
140140
}

src/coroutine/cotask.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,9 @@ void *cotask_yield(void *arg) {
577577

578578
static inline CoWaitResult cotask_wait_init(CoTaskData *task_data, char wait_type) {
579579
CoWaitResult wr = task_data->wait.result;
580-
memset(&task_data->wait, 0, sizeof(task_data->wait));
581-
task_data->wait.wait_type = wait_type;
580+
task_data->wait = (typeof(task_data->wait)) {
581+
.wait_type = wait_type,
582+
};
582583
return wr;
583584
}
584585

src/credits.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,10 @@ static void resize_fb(void *userdata, IntExtent *out_dimensions, FloatRect *out_
301301
}
302302

303303
static void credits_init(void) {
304-
memset(&credits, 0, sizeof(credits));
304+
credits = (typeof(credits)) {};
305305
stage3d_init(&stage_3d_context, 32);
306306

307-
FBAttachmentConfig a[2];
308-
memset(a, 0, sizeof(a));
307+
FBAttachmentConfig a[2] = {};
309308

310309
for(int i = 0; i < ARRAY_SIZE(a); i++) {
311310
a[i].tex_params.filter.min = TEX_FILTER_LINEAR;

src/dialog.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "resource/font.h"
1414

1515
void dialog_init(Dialog *d) {
16-
memset(d, 0, sizeof(*d));
16+
*d = (typeof(*d)) {};
1717
d->state = DIALOG_STATE_IDLE;
1818
d->text.current = &d->text.buffers[0];
1919
d->text.fading_out = &d->text.buffers[1];
@@ -31,18 +31,14 @@ void dialog_deinit(Dialog *d) {
3131
}
3232

3333
void dialog_add_actor(Dialog *d, DialogActor *a, const char *name, DialogSide side) {
34-
memset(a, 0, sizeof(*a));
35-
a->name = name;
36-
a->face = "normal";
37-
a->side = side;
38-
a->target_opacity = 1;
39-
a->composite_dirty = true;
40-
41-
if(side == DIALOG_SIDE_RIGHT) {
42-
a->speech_color = *RGB(0.6, 0.6, 1.0);
43-
} else {
44-
a->speech_color = *RGB(1.0, 1.0, 1.0);
45-
}
34+
*a = (typeof(*a)) {
35+
.name = name,
36+
.face = "normal",
37+
.side = side,
38+
.target_opacity = 1,
39+
.composite_dirty = true,
40+
.speech_color = (side == DIALOG_SIDE_RIGHT) ? *RGB(0.6, 0.6, 1.0) : *RGB(1.0, 1.0, 1.0),
41+
};
4642

4743
alist_append(&d->actors, a);
4844
}

src/dynarray.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void _dynarray_free_data(dynarray_size_t sizeof_element, DynamicArray *darr) {
2323
if(darr->capacity) {
2424
DYNARRAY_DEBUG(darr, "%u/%u", darr->num_elements, darr->capacity);
2525
}
26-
memset(darr, 0, sizeof(*darr));
26+
*darr = (typeof(*darr)) {};
2727
}
2828

2929
INLINE void _dynarray_resize(dynarray_size_t sizeof_element, DynamicArray *darr, dynarray_size_t capacity) {

0 commit comments

Comments
 (0)