Redesign of set_title causes problems

From: Christian Ejlertsen (
Date: 04/23/02


Worked on a flexible title command so that you can have pretitles.
Made it so you would set your title like this
title Sir * the Valiant Knight
This will resolve into Sir Playername the Valiant Knight.
It works sweetly actually, but then i wanted to add a check that
insured that the asteriks was in the title somewhere.
When the asteriks is found no problems, when no asterisk it goes 
through the if and sets it. It even prompts me that it has the set the
title, but then it's chrashes. it hangs like some sort of endless loop.
Gdb output is.
Program received signal SIGSEGV, segmentation fault.
0x400cf177 in malloc() from /lib/

What wrong ???

The set_title snippet is supplied below.


void set_title(struct char_data * ch, char *title)
  const char *i = NULL;
  char lbuf[MAX_STRING_LENGTH], *buf, *retitle;
  bool found = FALSE;

  buf = lbuf;

  if (title == NULL && !PLR_FLAGGED(ch, PLR_ROLLED)) {
    if (GET_SEX(ch) == SEX_FEMALE)
      title = title_female(GET_RACE(ch), GET_LEVEL(ch));
      title = title_male(GET_RACE(ch), GET_LEVEL(ch));

  if (strlen(title) > MAX_TITLE_LENGTH)
    title[MAX_TITLE_LENGTH] = '\0';

  if (GET_TITLE(ch) != NULL)

  for (;;) {
    if (*title == '*') {
        found = TRUE;
        i = GET_NAME(ch);
       while ((*buf = *(i++)))
    else if (!(*(buf++) = *(title++)))

  *(--buf) = '\0';

       /* if no asteriks (*) found reset title */
       if (!found) {
          if (GET_SEX(ch) == SEX_FEMALE) {
              retitle = title_female(GET_RACE(ch), GET_LEVEL(ch));
          else {
              retitle = title_male(GET_RACE(ch), GET_LEVEL(ch));
       send_to_char("Title has to contain the (*) asterisk sign to be valid!\r\n"
                           "Title reset to default.\r\n", ch);
        set_title(ch, retitle);

  GET_TITLE(ch) = str_dup(lbuf);

  sprintf(buf2, "Okay, you're now %s.\r\n", GET_TITLE(ch));
  send_to_char(buf2, ch);


Thanks in advance Christian

   | FAQ: |
   | Archives: |
   | Newbie List:   |

This archive was generated by hypermail 2b30 : 06/25/03 PDT