From: Christian Heller Date: Wed, 4 Sep 2013 00:59:57 +0000 (+0200) Subject: Removed some superfluous calloc()/malloc() calls. X-Git-Tag: tce~978 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/cards/%7B%7Bcard_id%7D%7D/condition?a=commitdiff_plain;h=2f0b15e05b0df7e10a2d0bb04ce4648455d980a8;p=plomrogue Removed some superfluous calloc()/malloc() calls. --- diff --git a/config/windows/toggle_order b/config/windows/toggle_order index 0b431e9..e45bc97 100644 --- a/config/windows/toggle_order +++ b/config/windows/toggle_order @@ -1 +1,2 @@ kmil + \ No newline at end of file diff --git a/src/command_db.c b/src/command_db.c index 0d4cb94..d5af5c2 100644 --- a/src/command_db.c +++ b/src/command_db.c @@ -88,8 +88,7 @@ extern void init_command_db(struct World * world) uint16_t lines, linemax; exit_err(textfile_sizes(file, &linemax, &lines), world, err_s); - char * line = malloc(linemax); - exit_err(NULL == line, world, err_m); + char line[linemax]; struct Command * cmds = malloc(lines * sizeof(struct Command)); exit_err(NULL == line, world, err_m); uint8_t i = 0; @@ -100,7 +99,6 @@ extern void init_command_db(struct World * world) copy_tokenized_string(world, &cmds[i].dsc_long, "\n", err_m); i++; } - free(line); exit_err(fclose(file), world, err_c); world->cmd_db = malloc(sizeof(struct CommandDB)); diff --git a/src/map_objects.c b/src/map_objects.c index 1507221..8b84ac1 100644 --- a/src/map_objects.c +++ b/src/map_objects.c @@ -107,8 +107,7 @@ extern void init_map_object_defs(struct World * world, char * filename) world->monster_def = 0; struct ItemDef * * p_p_id = &world->item_def; struct MonsterDef * * p_p_md = &world->monster_def; - char * defline = malloc(linemax); - exit_err(NULL == defline, world, err_m); + char defline[linemax]; char * line_p; char * delim = " "; while (fgets(defline, linemax, file)) @@ -148,7 +147,6 @@ extern void init_map_object_defs(struct World * world, char * filename) } } - free(defline); exit_err(fclose(file), world, err_c); } diff --git a/src/wincontrol.c b/src/wincontrol.c index d1a0304..b4a8640 100644 --- a/src/wincontrol.c +++ b/src/wincontrol.c @@ -96,8 +96,7 @@ static void init_winconf_from_file(struct World * world, char id) uint16_t linemax; exit_err(textfile_sizes(file, &linemax, NULL), world, err_s); - char * line = malloc(linemax); - exit_err(NULL == line, world, err_m); + char line[linemax]; struct WinConf * winconf = get_winconf_by_id(world, id); exit_err(NULL == fgets(line, linemax, file), world, err_g); @@ -117,7 +116,6 @@ static void init_winconf_from_file(struct World * world, char id) winconf->width_type = 1; } - free(line); exit_err(fclose(file), world, err_c); } @@ -137,7 +135,6 @@ static void init_win_from_winconf(struct World * world, char id) extern void save_win_config(struct World * world, char id) { char * err_o = "Trouble in save_win_config() with fopen()."; - char * err_m = "Trouble in save_win_config() with malloc()."; char * err_c = "Trouble in save_win_config() with fclose()."; char * err_u = "Trouble in save_win_config() with unlink()."; char * err_r = "Trouble in save_win_config() with rename()."; @@ -152,8 +149,7 @@ extern void save_win_config(struct World * world, char id) { size = 7; } - char * line = malloc(size); - exit_err(NULL == line, world, err_m); + char line[size]; sprintf(line, "%s\n", wc->title); fwrite(line, sizeof(char), strlen(line), file); sprintf(line, "%d\n", wc->height); @@ -352,7 +348,6 @@ extern void save_win_configs(struct World * world) save_win_config(world, 'm'); char * err_o = "Trouble in save_win_configs() with fopen()."; - char * err_m = "Trouble in save_win_configs() with calloc()."; char * err_c = "Trouble in save_win_configs() with fclose()."; char * err_u = "Trouble in save_win_configs() with unlink()."; char * err_r = "Trouble in save_win_configs() with rename()."; @@ -362,8 +357,7 @@ extern void save_win_configs(struct World * world) FILE * file = fopen(path_tmp, "w"); exit_err(NULL == file, world, err_o); - char * line = calloc(6, sizeof(char)); - exit_err(NULL == line, world, err_m); + char line[6]; struct Win * w_p = world->wmeta->_chain_start; uint8_t i = 0; while (0 != w_p)