search_block crash

From: Jon Barrett (mixtli@SINFO.NET)
Date: 02/28/98


  I have changed my color to be only on or off but ran into a few problems.
 When I type 'color on/off' it works fine, but if I type anything other
that on or off it will crash within search_block.

Here is the code.

static const char *ctypes[] = {"off", "on", "/n"};

ACMD(do_color)
{
  int tp;
  char arg2[MAX_INPUT_LENGTH];

  if (IS_NPC(ch))
    return;

  half_chop(argument, arg, arg2);
  //one_argument(argument, arg);

  if (!*arg) {
        show_color(ch);
    return;
  }
  if (((tp = search_block(arg, ctypes, FALSE)) == -1)) {
    send_to_char("Usage: color { On, Off }\r\n", ch);
    return;
  }
  if (!tp)
          REMOVE_BIT(PRF_FLAGS(ch), PRF_COLOR_ON);
  else {
          REMOVE_BIT(PRF_FLAGS(ch), PRF_COLOR_ON);
          SET_BIT(PRF_FLAGS(ch), PRF_COLOR_ON);
  }

  sprintf(buf, "Your /cRc/cGo/cYl/cBo/cPr/c0 is now %s.\r\n", ctypes[tp]);
  send_to_char(buf, ch);
}

int search_block(char *arg, const char **list, int exact)
{
  register int
i, l;

  /* Make into lower case, and get length of string */
  for (l = 0;
*(arg + l); l++)
    *(arg + l) = LOWER(*(arg + l));

  if (exact) {

for (i = 0; **(list + i) != '\n'; i++)
      if (!strcmp(arg, *(list +
i)))
        return (i);
  } else {
    if (!l)
      l = 1;                    /* Avoid "" to
match the first available
                                 * string */
    for (i = 0; **(list + i) !=
'\n'; i++) <------Error point to this line
      if (!strncmp(arg, *(list +
i), l))
        return (i);
  }

  return -1;
}

One more questio:  Why are the fill words taken out in one_argument, and
what would happen if they werent removed?

Thanks for the help...


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST