From: Christian Heller Date: Thu, 24 Jul 2014 00:39:13 +0000 (+0200) Subject: Server: Fix buggy evaluation of THING_ACTION id argument. X-Git-Tag: tce~696 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7Byoutube_prefix%7D%7D%7B%7Bvideo_data.id_%7D%7D?a=commitdiff_plain;h=51aa064d49b98de950dbcd7b154fa73d5d2eb359;p=plomrogue Server: Fix buggy evaluation of THING_ACTION id argument. --- diff --git a/src/server/god_commands.c b/src/server/god_commands.c index 8bde742..eee8b11 100644 --- a/src/server/god_commands.c +++ b/src/server/god_commands.c @@ -159,11 +159,6 @@ static uint8_t parse_thingaction_manipulation(char * tok0, char * tok1) } else if (parse_val(tok0, tok1, s[S_CMD_THINGACTION], '8', (char *) &id)) { - if (!id) - { - err_line(1, "Value must be >= 1 and <= 255."); - return 1; - } ta = get_thing_action(id); if (!ta) { diff --git a/src/server/things.c b/src/server/things.c index 2cb7db9..4097f61 100644 --- a/src/server/things.c +++ b/src/server/things.c @@ -28,15 +28,11 @@ struct NextAndId -/* Return lowest unused id for new thing ("sel"==0), thing type ("sel"==1) or - * thing action ("sel"==2). - */ -static uint8_t get_unused_id(uint8_t sel); - /* To linked list of NextAndId structs (or rather structs whose start region is * compatible to it) starting at "start", add newly allocated element of * "n_size" and an ID that is either "id" or, if "id" is <= UINT8_MAX and >= - * "id_start", get ID from get_unused_id("struct_id"). + * "id_start", get lowest ID for new thing ("struct_id"==0), thing type + * ("struct_id"==1) or thing action ("struct_id"==2). */ static struct NextAndId * add_to_struct_list(size_t n_size, uint8_t start_id, int16_t id, uint8_t struct_id, @@ -44,31 +40,32 @@ static struct NextAndId * add_to_struct_list(size_t n_size, uint8_t start_id, -static uint8_t get_unused_id(uint8_t sel) -{ - uint8_t i = 0; - while (1) - { - if ( (0 == sel && !get_thing(world.things, i, 1)) - || (1 == sel && !get_thing_type(i)) - || (2 == sel && !get_thing_action(i))) - { - return i; - } - exit_err(i == UINT8_MAX, "No unused ID available to add to ID list."); - i++; - } -} - - - static struct NextAndId * add_to_struct_list(size_t n_size, uint8_t start_id, int16_t id, uint8_t struct_id, struct NextAndId ** start) { struct NextAndId * nai = try_malloc(n_size, __func__); memset(nai, 0, n_size); - nai->id = (start_id<=id && id<=UINT8_MAX) ? id : get_unused_id(struct_id); + if (start_id <= id && id <= UINT8_MAX) + { + nai->id = id; + } + else + { + while (1) + { + if ( (0 == struct_id && !get_thing(world.things, start_id, 1)) + || (1 == struct_id && !get_thing_type(start_id)) + || (2 == struct_id && !get_thing_action(start_id))) + { + nai->id = start_id; + break; + } + char * err = "No unused ID available to add to ID list."; + exit_err(start_id == UINT8_MAX, err); + start_id++; + } + } struct NextAndId ** nai_ptr_ptr = start; for (; NULL != * nai_ptr_ptr; nai_ptr_ptr = &(*nai_ptr_ptr)->next); *nai_ptr_ptr = nai; @@ -77,11 +74,11 @@ static struct NextAndId * add_to_struct_list(size_t n_size, uint8_t start_id, -extern struct ThingAction * add_thing_action(int16_t id) +extern struct ThingAction * add_thing_action(uint8_t id) { struct ThingAction * ta; ta = (struct ThingAction *) add_to_struct_list(sizeof(struct ThingAction), - 1, id, 2, + 1, (int16_t) id, 2, (struct NextAndId **) &world.thing_actions); set_cleanup_flag(CLEANUP_THING_ACTIONS); diff --git a/src/server/things.h b/src/server/things.h index 6f7d124..599d877 100644 --- a/src/server/things.h +++ b/src/server/things.h @@ -53,7 +53,7 @@ struct ThingAction * s[S_CMD_WAIT], .func to actor_wait() and .effort to 1. If "id" is not >= 1 * and <= UINT8_MAX, use lowest unused id. Return thing action. */ -extern struct ThingAction * add_thing_action(int16_t id); +extern struct ThingAction * add_thing_action(uint8_t id); /* Add thing type of "id", with .corpse_id defaulting to "id" to * world.thing_types, .name to "(none)" and the remaining values to 0. If "id"