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

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

>Wayde Milas wrote:
>> 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
>    This is just a cut and paste from another post someone else made.  I
>did not write this, but it may help answer your question....
>My "zedit new <vnum>" now works after the following change:
>The fix is in zedit.c line 1174 :
>  /*. 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;
>  /*. Make a new zone in memory.*/
>  CREATE(new_table, struct zone_data,  top_of_zone_table+3);
>  new_table[top_of_zone_table + 1].number = 32000;
>I found the problem using purify, which just kept reporting that i was
>writing above the array bounds in new_table[], so i kept incrementing it
>until there were no more errors. I can understand why it should be
>top_of_zone_table+1, but why +3? (+1 and +2 still reported Array Bounds
>Write errors)

AH HA! ok, this is was the post I was looking for.

I'm still playing with gdb, but this is what I surmise so far:
its not +1 cause top_of_zone_table is the length, not including 0. so, the
length of zone_table is really top_of_zone_table+1;

It SHOULD be +2. the thing is, it looks like there is a null record or
something at the very end. I'm not quite sure on this. I can't see why
there is a null record, nor can I see why you would ever want to:
 new_table[top_of_zone_table + 1].number = 32000; since it doesn't make
sense anywhere. All the functions in db.c look like they loop through the
table by top_of_zone_table, not by looking for a null record on the end.

I'll play with the code tonight and mail the correct, working code to the
list tomorrow. :)


     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

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