From 651c99ff66ae4704021ee15136707c892ed243d6 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sat, 25 Jan 2014 18:28:46 +0100 Subject: [PATCH] Removed redundant calls for zeroing of memory, especially where replaceable with a single memset(ptr, 0, sizeof(struct ...)). --- src/client/keybindings.c | 2 -- src/client/windows.c | 17 ++++------------- src/server/map_objects.c | 8 ++------ 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/client/keybindings.c b/src/client/keybindings.c index fd62dda..2990419 100644 --- a/src/client/keybindings.c +++ b/src/client/keybindings.c @@ -208,8 +208,6 @@ extern void read_keybindings_from_file(char * line, uint32_t linemax, kb_p->command = get_command(cmdptr); loc_last_ptr = & kb_p->next; } - kbd->edit = 0; - kbd->select = 0; } diff --git a/src/client/windows.c b/src/client/windows.c index 2d5dd3a..572fccd 100644 --- a/src/client/windows.c +++ b/src/client/windows.c @@ -10,7 +10,7 @@ #include /* free(), atoi() */ #include /* uint8_t, uint16_t, uint32_t, UINT16_MAX */ #include /* sprintf() */ -#include /* memcpy(), strlen(), strnlen(), strchr() */ +#include /* memcpy(), strlen(), strnlen(), strchr(), memset() */ #include "../common/rexit.h" /* exit_trouble(), exit_err() */ #include "../common/readwrite.h" /* try_fputc(), try_write(), try_fgets(), * try_fgetc() @@ -485,8 +485,7 @@ static void draw_wins(struct Win * w) } free(w->winmap); w->winmap = NULL; - w->winmap_size.y = 0; - w->winmap_size.x = 0; + memset(&w->winmap_size, 0, sizeof(struct yx_uint16)); if (offset_y > 0) { winscroll_hint(w, '^', offset_y + 1); @@ -631,6 +630,7 @@ extern uint8_t read_winconf_from_file(char * line, uint32_t linemax, return 0; } struct Win win; + memset(&win, 0, sizeof(struct Win)); win.id = (char) test; try_fgetc(file, f_name); try_fgets(line, linemax + 1, file, f_name); @@ -644,14 +644,6 @@ extern uint8_t read_winconf_from_file(char * line, uint32_t linemax, win.target_width = atoi(line); win.target_width_type = (0 >= win.target_width); read_keybindings_from_file(line, linemax, file, &win.kb); - win.view = 0; - win.target_center.y = 0; - win.target_center.x = 0; - win.winmap_size.y = 0; - win.winmap_size.x = 0; - win.winmap = NULL; - win.center.y = 0; - win.center.x = 0; add_win_to_windb(&win); return 1; } @@ -845,8 +837,7 @@ extern void toggle_winconfig() { w->view = 1; w->target_center = w->center; - w->center.y = 0; - w->center.x = 0; + memset(&w->center, 0, sizeof(struct yx_uint16)); return; } else if (1 == w->view) diff --git a/src/server/map_objects.c b/src/server/map_objects.c index 648631e..abcb6ac 100644 --- a/src/server/map_objects.c +++ b/src/server/map_objects.c @@ -5,7 +5,7 @@ #include /* FILE typedef */ #include /* uint8_t, uint16_t */ #include /* free(), atoi() */ -#include /* strlen(), memcpy(), strtok() */ +#include /* strlen(), memcpy(), strtok(), memset() */ #include "../common/readwrite.h" /* try_fopen(), try_fclose(), try_fgets(), * textfile_sizes() */ @@ -67,6 +67,7 @@ static void add_map_object(uint8_t type) char * f_name = "add_map_object()"; struct MapObjDef * mod = get_map_object_def(type); struct MapObj * mo = try_malloc(sizeof(struct MapObj), f_name); + memset(mo, 0, sizeof(struct MapObj)); mo->id = world.map_obj_count++; mo->type = mod->id; mo->lifepoints = mod->lifepoints; @@ -89,11 +90,6 @@ static void add_map_object(uint8_t type) break; } } - mo->progress = 0; - mo->command = 0; - mo->arg = 0; - mo->owns = NULL; - mo->next = NULL; struct MapObj ** mo_ptr_ptr = &world.map_objs; for (; NULL != * mo_ptr_ptr; mo_ptr_ptr = &(*mo_ptr_ptr)->next); * mo_ptr_ptr = mo; -- 2.30.2