From 491e8bc8e7a9b1d312256817c0b8be7e05b127be Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sun, 17 Aug 2014 04:26:47 +0200 Subject: [PATCH] Remove redundant uses of NULL. --- src/client/command_db.c | 2 +- src/client/interface_conf.c | 4 ++-- src/client/io.c | 4 ++-- src/client/parse.c | 4 ++-- src/client/wincontrol.c | 2 +- src/client/windows.c | 2 +- src/common/readwrite.c | 4 ++-- src/common/rexit.c | 2 +- src/common/try_malloc.c | 4 ++-- src/server/ai.c | 5 ++--- src/server/field_of_view.c | 4 ++-- src/server/god_commands.c | 2 +- src/server/init.c | 12 ++++++------ src/server/io.c | 6 +++--- src/server/run.c | 8 ++++---- src/server/thing_actions.c | 10 +++++----- src/server/things.c | 24 ++++++++++++------------ 17 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/client/command_db.c b/src/client/command_db.c index a7523b7..34ca821 100644 --- a/src/client/command_db.c +++ b/src/client/command_db.c @@ -64,7 +64,7 @@ static void tokens_into_entries(char * token0, char * token1) cmd = (struct Command *) parse_init_entry(&cmd_flags, sizeof(struct Command)); cmd->dsc_short = strdup(token1); - parse_id_uniq(NULL != get_command(cmd->dsc_short)); + parse_id_uniq(!(!get_command(cmd->dsc_short))); } else if (!( parse_flagval(token0, token1, "DESCRIPTION", &cmd_flags, DESC_SET, 's', (char *) &cmd->dsc_long) diff --git a/src/client/interface_conf.c b/src/client/interface_conf.c index 9e97c55..45abd6a 100644 --- a/src/client/interface_conf.c +++ b/src/client/interface_conf.c @@ -243,7 +243,7 @@ static uint8_t start_win(char * token0, char * token1, char * str_win, } *win = (struct Win *) parse_init_entry(win_flags, sizeof(struct Win)); parsetest_singlechar(token1); - parse_id_uniq(world.winDB.ids && (NULL!=strchr(world.winDB.ids,token1[0]))); + parse_id_uniq(world.winDB.ids && strchr(world.winDB.ids,token1[0])); (*win)->id = token1[0]; return 1; } @@ -367,7 +367,7 @@ static void set_keybindings(char * token1, uint8_t flags, } kb.keycode = atoi(token1); char * err_uniq = "Binding to key already defined."; - err_line(NULL != get_command_to_keycode(kbdb, kb.keycode), err_uniq); + err_line(!(!get_command_to_keycode(kbdb, kb.keycode)), err_uniq); kb.command = get_command(token2); err_line(!(kb.command), "No such command in command DB."); array_append(kbdb->n_of_kbs, sizeof(struct KeyBinding), (void *) &kb, diff --git a/src/client/io.c b/src/client/io.c index c0cf977..39fd75e 100644 --- a/src/client/io.c +++ b/src/client/io.c @@ -98,7 +98,7 @@ static void read_inventory(char * read_buf, uint32_t linemax, FILE * file) break; } int old_size = 0; - if (NULL != world.player_inventory) + if (world.player_inventory) { old_size = strlen(world.player_inventory); } @@ -146,7 +146,7 @@ static void read_log(char * read_buf, uint32_t linemax, FILE * file) while (try_fgets(read_buf, linemax + 1, file, __func__)) { int old_size = 0; - if (NULL != world.log) + if (world.log) { old_size = strlen(world.log); } diff --git a/src/client/parse.c b/src/client/parse.c index 54d8fc3..c233a92 100644 --- a/src/client/parse.c +++ b/src/client/parse.c @@ -31,7 +31,7 @@ extern void parse_file(char * path, void (* token_to_entry) (char *, char *)) char * errline_line = try_malloc(linemax + 1, __func__); set_err_line_options(errline_intro, errline_line, 1); err_line_zero(); - err_line(0 == linemax, "File is empty."); + err_line(!linemax, "File is empty."); char * token0 = NULL; /* For final token_to_entry() if while() stagnates. */ char * token1 = NULL; char * err_val = "No value given."; @@ -65,7 +65,7 @@ extern void parsetest_defcontext(uint8_t flags) extern void parsetest_too_many_values() { - err_line(NULL != token_from_line(NULL), "Too many values."); + err_line(!(!token_from_line(NULL)), "Too many values."); } diff --git a/src/client/wincontrol.c b/src/client/wincontrol.c index 85750ec..7dadbc8 100644 --- a/src/client/wincontrol.c +++ b/src/client/wincontrol.c @@ -220,7 +220,7 @@ static void suspend_win(struct Win * w) extern void toggle_window(char id) { struct Win * win = get_win_by_id(id); - if (NULL == strchr(world.winDB.order, id)) + if (!strchr(world.winDB.order, id)) { append_win(win); return; diff --git a/src/client/windows.c b/src/client/windows.c index 3881393..14cf9b2 100644 --- a/src/client/windows.c +++ b/src/client/windows.c @@ -400,7 +400,7 @@ extern void make_v_screen_and_init_win_sizes() world.winDB.v_screen_size.y = maxy_test; world.winDB.v_screen_size.x = maxx_test; world.winDB.v_screen = newpad(world.winDB.v_screen_size.y, 1); - exit_trouble(NULL == world.winDB.v_screen, __func__, err_m); + exit_trouble(!world.winDB.v_screen, __func__, err_m); char id; while (0 != (id = get_next_win_id())) { diff --git a/src/common/readwrite.c b/src/common/readwrite.c index ac7b56a..a206c9c 100644 --- a/src/common/readwrite.c +++ b/src/common/readwrite.c @@ -26,7 +26,7 @@ extern FILE * try_fopen(char * path, char * mode, const char * f) int test = sprintf(msg, "%s%s%s%s%s%s%s", msg1,f,msg2,mode,msg3,path,msg4); exit_trouble(test < 0, __func__, "sprintf"); FILE * file_p = fopen(path, mode); - exit_err(NULL == file_p, msg); + exit_err(!file_p, msg); free(msg); return file_p; } @@ -68,7 +68,7 @@ extern int try_fgetc(FILE * file, const char * f) extern char * try_fgets(char * line, int linemax, FILE * file, const char * f) { char * test = fgets(line, linemax, file); - exit_trouble(NULL == test && ferror(file), f, "fgets"); + exit_trouble(!test && ferror(file), f, "fgets"); return test; } diff --git a/src/common/rexit.c b/src/common/rexit.c index a3e18b2..b528975 100644 --- a/src/common/rexit.c +++ b/src/common/rexit.c @@ -28,7 +28,7 @@ extern void exit_err(int err, const char * msg) return; } cleanup_func(); - if (NULL == msg) + if (!msg) { msg = "Details unknown."; } diff --git a/src/common/try_malloc.c b/src/common/try_malloc.c index 81e75bf..41d80c9 100644 --- a/src/common/try_malloc.c +++ b/src/common/try_malloc.c @@ -13,12 +13,12 @@ extern void * try_malloc(size_t size, const char * f) { char * prefix = "Trouble with malloc in "; char * msg = malloc(strlen(prefix) + strlen(f) + 1 + 1); - exit_err(NULL == msg, + exit_err(!msg, "Trouble in try_malloc with malloc for error message string."); int test = sprintf(msg, "%s%s.", prefix, f); exit_err(test < 0, "Trouble in try_malloc with sprintf."); void * p = malloc(size); - exit_err(NULL == p, msg); /* Bypass exit_trouble() calling try_malloc(). */ + exit_err(!p, msg); /* Bypass exit_trouble() calling try_malloc(). */ free(msg); return p; } diff --git a/src/server/ai.c b/src/server/ai.c index cdefca8..630c2db 100644 --- a/src/server/ai.c +++ b/src/server/ai.c @@ -1,7 +1,6 @@ /* src/server/ai.c */ #include "ai.h" -#include /* NULL */ #include /* uint8_t, uint16_t, uint32_t, int16_t, UINT16_MAX */ #include /* free() */ #include "../common/try_malloc.h" /* try_malloc() */ @@ -268,7 +267,7 @@ static int16_t get_inventory_slot_to_consume(struct Thing * t_owner) int16_t selection = -1; struct Thing * t = t_owner->owns;; uint8_t i; - for (i = 0; t != NULL; t = t->next, i++) + for (i = 0; t; t = t->next, i++) { struct ThingType * tt = get_thing_type(t->type); if (tt->consumable > compare_consumability) @@ -285,7 +284,7 @@ static int16_t get_inventory_slot_to_consume(struct Thing * t_owner) static uint8_t standing_on_consumable(struct Thing * t_standing) { struct Thing * t = world.things; - for (; t != NULL; t = t->next) + for (; t; t = t->next) { if ( t != t_standing && t->pos.y == t_standing->pos.y && t->pos.x == t_standing->pos.x) diff --git a/src/server/field_of_view.c b/src/server/field_of_view.c index 4b1ac00..07e1455 100644 --- a/src/server/field_of_view.c +++ b/src/server/field_of_view.c @@ -374,7 +374,7 @@ static void update_map_memory(struct Thing * t_eye, uint32_t map_size) struct ThingInMemory * tm = t_eye->t_mem; struct ThingInMemory * tm_prev = NULL; struct ThingInMemory * tm_next = NULL; - for (; tm != NULL; tm = tm_next) + for (; tm; tm = tm_next) { tm_next = tm->next; if ('v' == t_eye->fov_map[tm->pos.y * world.map.length + tm->pos.x]) @@ -393,7 +393,7 @@ static void update_map_memory(struct Thing * t_eye, uint32_t map_size) tm_prev = tm; } struct Thing * t = world.things; - for (; t != NULL; t = t->next) + for (; t; t = t->next) { if ( !t->lifepoints && 'v' == t_eye->fov_map[t->pos.y * world.map.length + t->pos.x]) diff --git a/src/server/god_commands.c b/src/server/god_commands.c index 09aeece..420142a 100644 --- a/src/server/god_commands.c +++ b/src/server/god_commands.c @@ -301,7 +301,7 @@ static uint8_t parse_thing_manipulation_1arg(char * tok0, char * tok1) { t = get_thing(world.things, id, 1); char * err = "No thing type found to initialize new thing."; - if (!t && !err_line(NULL == world.thing_types, err)) + if (!t && !err_line(!world.thing_types, err)) { t = add_thing(id, world.thing_types->id, 0, 0); if (world.exists && t->lifepoints) diff --git a/src/server/init.c b/src/server/init.c index 49ba22a..aa5761c 100644 --- a/src/server/init.c +++ b/src/server/init.c @@ -55,7 +55,7 @@ static void obey_lines_from_file(char * path, uint8_t record) FILE * file = try_fopen(path, "r", __func__); uint32_t linemax = textfile_width(file); char * line = try_malloc(linemax + 1, __func__); - while (NULL != try_fgets(line, linemax + 1, file, __func__)) + while (try_fgets(line, linemax + 1, file, __func__)) { if (strlen(line)) { @@ -84,7 +84,7 @@ static void replay_game() uint32_t linemax = textfile_width(file); char * line = try_malloc(linemax + 1, __func__); while ( world.turn < world.replay - && NULL != try_fgets(line, linemax + 1, file, __func__)) + && try_fgets(line, linemax + 1, file, __func__)) { obey_msg(line, 0, 1); err_line_inc(); @@ -112,7 +112,7 @@ static uint8_t world_cannot_be_made() { uint8_t player_will_be_generated = 0; struct ThingType * tt; - for (tt = world.thing_types; NULL != tt; tt = tt->next) + for (tt = world.thing_types; tt; tt = tt->next) { if (world.player_type == tt->id) { @@ -197,7 +197,7 @@ extern uint8_t remake_world() free_things(world.things); remake_map(); struct ThingType * tt; - for (tt = world.thing_types; NULL != tt; tt = tt->next) + for (tt = world.thing_types; tt; tt = tt->next) { if (world.player_type == tt->id) { @@ -205,7 +205,7 @@ extern uint8_t remake_world() break; } } - for (tt = world.thing_types; NULL != tt; tt = tt->next) + for (tt = world.thing_types; tt; tt = tt->next) { if (world.player_type != tt->id) { @@ -213,7 +213,7 @@ extern uint8_t remake_world() } } struct Thing * t; - for (t = world.things; NULL != t; t = t->next) + for (t = world.things; t; t = t->next) { if (t->lifepoints) { diff --git a/src/server/io.c b/src/server/io.c index 8f8f738..d8190c6 100644 --- a/src/server/io.c +++ b/src/server/io.c @@ -289,7 +289,7 @@ static void write_value_as_line(uint32_t value, FILE * file) static void write_inventory(struct Thing * player, FILE * file) { struct Thing * owned = player->owns; - if (NULL == owned) + if (!owned) { char * empty = "(none)\n"; try_fwrite(empty, strlen(empty), 1, file, __func__); @@ -297,7 +297,7 @@ static void write_inventory(struct Thing * player, FILE * file) else { uint8_t q; - for (q = 0; NULL != owned; q++) + for (q = 0; owned; q++) { struct ThingType * tt = get_thing_type(owned->type); try_fwrite(tt->name, strlen(tt->name), 1, file, __func__); @@ -372,7 +372,7 @@ static void write_map(struct Thing * player, FILE * file) struct ThingInMemory * tm; for (i = 0; i < 2; i++) { - for (tm = player->t_mem; tm != NULL; tm = tm->next) + for (tm = player->t_mem; tm; tm = tm->next) { if (' ' != player->mem_map[tm->pos.y*world.map.length+tm->pos.x]) { diff --git a/src/server/run.c b/src/server/run.c index 906bed2..786b280 100644 --- a/src/server/run.c +++ b/src/server/run.c @@ -208,7 +208,7 @@ static void turn_over() while ( 0 < player->lifepoints || (0 == player->lifepoints && start_turn == world.turn)) { - if (NULL == thing) + if (!thing) { world.turn++; thing = world.things; @@ -285,7 +285,7 @@ extern void obey_msg(char * msg, uint8_t do_record, uint8_t do_verbose) set_err_line_options("Trouble with message: ", msg, 0); char * msg_copy = strdup(msg); char * tok0 = token_from_line(msg_copy); - if (NULL != tok0) + if (tok0) { if (parse_command(tok0)) @@ -299,7 +299,7 @@ extern void obey_msg(char * msg, uint8_t do_record, uint8_t do_verbose) record(msg, 0); } char * tokplus = token_from_line(NULL); - err_line(NULL != tokplus, "Too many arguments, ignoring overflow."); + err_line(!(!tokplus), "Too many arguments, ignoring overflow."); free(msg_copy); return; } @@ -316,7 +316,7 @@ extern uint8_t io_loop() { char * msg = io_round(); server_test(); - if (NULL == msg) + if (!msg) { continue; } diff --git a/src/server/thing_actions.c b/src/server/thing_actions.c index 40a44ba..ec713ae 100644 --- a/src/server/thing_actions.c +++ b/src/server/thing_actions.c @@ -286,7 +286,7 @@ extern void actor_move(struct Thing * t) extern void actor_drop(struct Thing * t) { - uint8_t owns_none = (NULL == t->owns); + uint8_t owns_none = (!t->owns); if (!owns_none) { uint8_t select = t->arg; @@ -307,21 +307,21 @@ extern void actor_pick(struct Thing * t) { struct Thing * picked = NULL; struct Thing * t_i; - for (t_i = world.things; NULL != t_i; t_i = t_i->next) + for (t_i = world.things; t_i; t_i = t_i->next) { if (t_i != t && yx_uint8_cmp(&t_i->pos, &t->pos)) { picked = t_i; } } - if (NULL != picked) + if (picked) { own_thing(&t->owns, &world.things, picked->id); set_thing_position(picked, t->pos); } if (t == get_player()) { - playerbonus_pick(NULL != picked); + playerbonus_pick(!(!picked)); } } @@ -330,7 +330,7 @@ extern void actor_pick(struct Thing * t) extern void actor_use(struct Thing * t) { uint8_t wrong_thing = 1; - uint8_t no_thing = (NULL == t->owns); + uint8_t no_thing = (!t->owns); if (!no_thing) { uint8_t select = t->arg; diff --git a/src/server/things.c b/src/server/things.c index 7d0f62d..bbe9dbf 100644 --- a/src/server/things.c +++ b/src/server/things.c @@ -45,7 +45,7 @@ static struct NextAndId * add_to_struct_list(size_t n_size, uint8_t start_id, static void free_things_in_memory(struct ThingInMemory * tm) { - if (NULL == tm) + if (!tm) { return; } @@ -82,7 +82,7 @@ static struct NextAndId * add_to_struct_list(size_t n_size, uint8_t start_id, } } struct NextAndId ** nai_ptr_ptr = start; - for (; NULL != * nai_ptr_ptr; nai_ptr_ptr = &(*nai_ptr_ptr)->next); + for (; * nai_ptr_ptr; nai_ptr_ptr = &(*nai_ptr_ptr)->next); *nai_ptr_ptr = nai; return nai; } @@ -151,7 +151,7 @@ extern void add_thing_to_memory_map(struct Thing * t, uint8_t type, extern void free_thing_actions(struct ThingAction * ta) { - if (NULL == ta) + if (!ta) { return; } @@ -164,7 +164,7 @@ extern void free_thing_actions(struct ThingAction * ta) extern void free_thing_types(struct ThingType * tt) { - if (NULL == tt) + if (!tt) { return; } @@ -177,7 +177,7 @@ extern void free_thing_types(struct ThingType * tt) extern void free_things(struct Thing * t) { - if (NULL == t) + if (!t) { return; } @@ -198,7 +198,7 @@ extern void free_things(struct Thing * t) extern struct ThingAction * get_thing_action(uint8_t id) { struct ThingAction * ta = world.thing_actions; - for (; NULL != ta && id != ta->id; ta = ta->next); + for (; ta && id != ta->id; ta = ta->next); return ta; } @@ -207,7 +207,7 @@ extern struct ThingAction * get_thing_action(uint8_t id) extern struct ThingType * get_thing_type(uint8_t id) { struct ThingType * tt = world.thing_types; - for (; NULL != tt && id != tt->id; tt = tt->next); + for (; tt && id != tt->id; tt = tt->next); return tt; } @@ -216,7 +216,7 @@ extern struct ThingType * get_thing_type(uint8_t id) extern uint8_t get_thing_action_id_by_name(char * name) { struct ThingAction * ta = world.thing_actions; - while (NULL != ta) + while (ta) { if (0 == strcmp(ta->name, name)) { @@ -237,14 +237,14 @@ extern struct Thing * get_thing(struct Thing * ptr, uint8_t id, uint8_t deep) { while (1) { - if (NULL == ptr || id == ptr->id) + if (!ptr || id == ptr->id) { return ptr; } if (deep) { struct Thing * owned_thing = get_thing(ptr->owns, id, 1); - if (NULL != owned_thing) + if (owned_thing) { return ptr; } @@ -324,7 +324,7 @@ extern void own_thing(struct Thing ** target, struct Thing ** source, penult->next = t->next; } struct Thing ** t_ptr_ptr = target; - for (; NULL != * t_ptr_ptr; t_ptr_ptr = &(*t_ptr_ptr)->next); + for (; * t_ptr_ptr; t_ptr_ptr = &(*t_ptr_ptr)->next); * t_ptr_ptr = t; t->next = NULL; } @@ -335,5 +335,5 @@ extern void set_thing_position(struct Thing * t, struct yx_uint8 pos) { t->pos = pos; struct Thing * owned = t->owns; - for (; owned != NULL; set_thing_position(owned, pos), owned = owned->next); + for (; owned; set_thing_position(owned, pos), owned = owned->next); } -- 2.30.2