Re: TRIGEDIT crashes mud?

From: Thomas Arp (t_arp@stofanet.dk)
Date: 02/23/03


From: "Kevin Dethlefs" <Demortes2004@aol.com>
> Line 3227 in dg_scripts.c:
> int real_trigger(int vnum)
> {
>   int bot = 0, mid;
>   int top = top_of_trigt;
>
>   /* perform binary search on trigger-table */
>   for (;;) {
>     mid = (bot + top) / 2;
>
> 3227:if (trig_index[mid]->vnum == vnum)
>       return (mid);
>     if (bot >= top)
>       return (NOTHING);
>     if (trig_index[mid]->vnum > vnum)
>       top = mid - 1;
>     else
>       bot = mid + 1;
>   }
> }
>
Ack! I thought I'd sent out the patch with the correct real_trigger
function already. Anyway, the logic is busted in this example.
Here's the latest (and working) version:

/* returns the real number of the trigger with given virtual number */
int real_trigger(int vnum)
{
  int bot = 0, mid;
  int top = top_of_trigt-1;

  /* perform binary search on trigger-table */
  for (;;) {
    mid = (bot + top) / 2;

  /* Thanks to Derek Fisk for fixing this loop */
    if (bot > top)
      return (NOTHING);
    if (trig_index[mid]->vnum == vnum)
      return (mid);
    if (trig_index[mid]->vnum > vnum)
      top = mid - 1;
    else
      bot = mid + 1;
  }
}

Welcor

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



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