Confusing code fix (#76)

* Make sure all followers are free'd before freeing the character list

Otherwise, the followers structs will point to free'd memory and
the stop_follower call will attempt to dereference a free'd
characters' followers list.

* Make sure %target% works in act triggers

* code cleanup. Remove inline block, make variable names more understandable.

Ref https://www.tbamud.com/forum/4-development/4525-confused-over-piece-of-code-in-parse-room
This commit is contained in:
Thomas Arp 2020-01-26 22:19:10 +01:00 committed by wyld-sw
parent 1ab51a0545
commit 7f0acefcb4
2 changed files with 21 additions and 12 deletions

View file

@ -2495,7 +2495,7 @@ void perform_act(const char *orig, struct char_data *ch, struct obj_data *obj,
const char *i = NULL;
char lbuf[MAX_STRING_LENGTH], *buf, *j;
bool uppercasenext = FALSE;
struct char_data *dg_victim = NULL;
struct char_data *dg_victim = (to == vict_obj) ? vict_obj : NULL;
struct obj_data *dg_target = NULL;
char *dg_arg = NULL;

View file

@ -1239,6 +1239,24 @@ static bitvector_t asciiflag_conv_aff(char *flag)
return (flags);
}
/* Fix for crashes in the editor when formatting. E-descs are assumed to
* end with a \r\n. -Welcor */
void ensure_newline_terminated(struct extra_descr_data* new_descr) {
char *with_term, *end;
if (new_descr->description == NULL) {
return;
}
end = strchr(new_descr->description, '\0');
if (end > new_descr->description && *(end - 1) != '\n') {
CREATE(with_term, char, strlen(new_descr->description) + 3);
sprintf(with_term, "%s\r\n", new_descr->description); /* snprintf ok : size checked above*/
free(new_descr->description);
new_descr->description = with_term;
}
}
/* load the rooms */
void parse_room(FILE *fl, int virtual_nr)
{
@ -1346,17 +1364,8 @@ void parse_room(FILE *fl, int virtual_nr)
CREATE(new_descr, struct extra_descr_data, 1);
new_descr->keyword = fread_string(fl, buf2);
new_descr->description = fread_string(fl, buf2);
/* Fix for crashes in the editor when formatting. E-descs are assumed to
* end with a \r\n. -Welcor */
{
char *end = strchr(new_descr->description, '\0');
if (end > new_descr->description && *(end-1) != '\n') {
CREATE(end, char, strlen(new_descr->description)+3);
sprintf(end, "%s\r\n", new_descr->description); /* snprintf ok : size checked above*/
free(new_descr->description);
new_descr->description = end;
}
}
ensure_newline_terminated(new_descr);
new_descr->next = world[room_nr].ex_description;
world[room_nr].ex_description = new_descr;
break;