copy_tokenized_string(line, &world.cmd_db.cmds[i].dsc_short, delim);
copy_tokenized_string(NULL, &world.cmd_db.cmds[i].server_msg, delim);
if (!strcmp("0", world.cmd_db.cmds[i].server_msg))
- {
- free(world.cmd_db.cmds[i].server_msg);
- world.cmd_db.cmds[i].server_msg = NULL;
- }
+ { /* .server_msg==0 detects */
+ free(world.cmd_db.cmds[i].server_msg); /* non-server commands in */
+ world.cmd_db.cmds[i].server_msg = NULL;/* control.h's try_key() / */
+ } /* try_server_command(). */
char * arg_string = strtok(NULL, delim);
world.cmd_db.cmds[i].arg = arg_string[0];
copy_tokenized_string(NULL, &world.cmd_db.cmds[i].dsc_long, "\n");
win->center.y = world.player_inventory_select;
char inventory_copy[strlen(world.player_inventory) + 1];
sprintf(inventory_copy, "%s", world.player_inventory);
- char * foo = inventory_copy;
+ char * strtok_target = inventory_copy;
uint8_t i = 0;
while (1)
{
- char * object = strtok(foo, "\n");
- foo = NULL;
+ char * object = strtok(strtok_target, "\n");
+ strtok_target = NULL;
if (NULL == object)
{
return;
#include <fcntl.h> /* open() */
#include <limits.h> /* PIPE_BUF */
#include <ncurses.h> /* halfdelay(), getch() */
+#include <stddef.h> /* NULL */
#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
#include <stdio.h> /* FILE, sprintf(), fseek() */
#include <string.h> /* strcmp(), strlen(), memcpy() */
char * f_name = "read_inventory()";
char * delimiter = "%\n";
free(world.player_inventory);
- world.player_inventory = NULL;
+ world.player_inventory = NULL; /* Avoids illegal strlen() below. */
while (1)
{
try_fgets(read_buf, linemax + 1, file, f_name);
#include <ncurses.h> /* keypad() */
#include <signal.h> /* struct sigaction, sigaction() */
+#include <stddef.h> /* NULL */
#include <stdlib.h> /* exit() */
#include <string.h> /* memset() */
#include "../common/rexit.h" /* set_cleanup_func(), exit_trouble() */
extern void unload_interface_conf()
{
free_keybindings(world.kb_global.kbs);
- world.kb_global.kbs = NULL;
free_keybindings(world.kb_wingeom.kbs);
- world.kb_wingeom.kbs = NULL;
free_keybindings(world.kb_winkeys.kbs);
- world.kb_winkeys.kbs = NULL;
while ('\0' != world.windb.active)
{
toggle_window(world.windb.active);
w->start.x + (x - offset_x), ch);
}
}
- free(w->winmap);
- w->winmap = NULL;
+ free(w->winmap); /* NULL so draw_wins.c's try_resize_winmap() may always */
+ w->winmap = NULL;/* free() it before (re-)allocation, even the first time.*/
memset(&w->winmap_size, 0, sizeof(struct yx_uint16));
if (offset_y > 0)
{
free(wc->title);
free_keybindings(wc->kb.kbs);
}
- free(world.windb.ids);
- world.windb.ids = NULL;
+ free(world.windb.ids); /* NULL this too since add_win_to_windb() checks */
+ world.windb.ids = NULL; /* for it to detect its first post-DB-purge round.*/
free(world.windb.wins);
- world.windb.wins = NULL;
free(world.windb.order);
- world.windb.order = NULL;
}
extern void remake_world(uint32_t seed)
{
free(world.log);
- world.log = NULL;
+ world.log = NULL; /* map_object_action.c's update_log() checks for this. */
world.seed = seed;
world.map_obj_count = 0;
world.score = 0;
free(world.map.cells);
- if (world.map_objs)
- {
- free_map_objects(world.map_objs);
- }
+ free_map_objects(world.map_objs);
world.last_update_turn = 0;
world.turn = 1;
init_map();
world.queue_size = world.queue_size - cutout_len;
if (0 == world.queue_size)
{
- free(world.queue);
- world.queue = NULL;
+ free(world.queue); /* NULL so read_fifo_into_queue() may free() this */
+ world.queue = NULL; /* every time, even when it's un-allocated first. */
}
else
{
free_map_object_defs(mod_start->next);
free(mod_start->name);
free(mod_start);
- mod_start = NULL;
}
free_map_objects(mo_start->owns);
free_map_objects(mo_start->next);
free(mo_start);
- if (mo_start == world.map_objs)
- {
- world.map_objs = NULL;
- }
+ if (mo_start == world.map_objs) /* So add_map_objects()' NULL-delimited */
+ { /* map object iteration loop does not */
+ world.map_objs = NULL; /* iterate over freed memory when called */
+ } /* the 1st time after world re-seeding. */
}