Re: [CODE] Zedit (yea, again...)

From: Wayde Milas (thebard@RARLOA-4.PR.MCS.NET)
Date: 07/23/97


after taking a good look at zedit.c, I guess it all comes down to the
following chunk of code:

/*. Make a new zone in memory.*/
  CREATE(new_table, struct zone_data, top_of_zone_table);
  new_table[top_of_zone_table + 1].number = 32000;
  for(i = 0; i <= top_of_zone_table + 1; i++)
    if(!found)
      if (i > top_of_zone_table || zone_table[i].number > vzone_num)
      { found = 1;
        new_table[i].name = str_dup("New Zone");
        new_table[i].number = vzone_num;
        new_table[i].top = (vzone_num * 100) + 99;
        new_table[i].lifespan = 30;
        new_table[i].age = 0;
        new_table[i].reset_mode = 2;
        CREATE(new_table[i].cmd, struct reset_com, 1);
        new_table[i].cmd[0].command = 'S';
        if (i <= top_of_zone_table)
          new_table[i+1] = zone_table[i];
      } else
        new_table[i] = zone_table[i];
    else
      new_table[i+1] = zone_table[i];
  free(zone_table);
  zone_table = new_table;
  top_of_zone_table++;


Question. Isn't the second line totally wrong? if you calloc an array of
top_of_zone_table size, and then you set an element in
new_table[top_of_zone_table + 1] (number) aren't you WAY past the end of
the new array that you allocated?

Not only that... but you are actually 2 spaces past it since you have to
consider that they array starts at [0].

So, is it me, or does this piece of code look totally fubared? I think its
time for me to re-write it. :)

Wayde


     +------------------------------------------------------------+
     | 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/08/00 PST