--- [EMAIL PROTECTED] wrote:
> Here is my code:
> 
>  if ( IS_SET(container->value[1], CONT_CLOSED) )
>     {
>         act( "The $d is closed.", ch, NULL, container->name, TO_CHAR );
>         return;
>     }
> 
> /*end of normal do_put*/
> /*Start object count*/
>     count = 0;
>     for ( container = container->contains; container != NULL; container = 
> container->next_content)
>        {
>            count++;
>            printf("count %d\n\r", count);
>            printf("value 3: %d\n\r", container->value[3]);
>        }

Ok, so before the loop, container pointed to the object you were trying to put
something in. Then the loop initializes container to be the first object inside
the container. Then you are using the value[3] for the first item in the
container and comparing it to the count. Then you keep doing that for each item
in the original container (which you've unfortunately lost your pointer for).
Each time you increment count, and output the count, and the value[3] for the
item in the container. Then you finally end the loop when container equals NULL
because you are at the end of the contains list.

>      /*End object count, start comparison*/   
>     if (container->value[3] <= count)
>         {
>                 stc("Too many items.\n\r", ch);
>                 return;
>         }

Here you are trying to check the container->value[3]. Unfortunately, container
doesn't point to the actual container anymore, because you reused your pointer
as an iterator in your for loop. It doesn't even point to an object in the
container since you've already iterated through the whole list. No, this
pointer now points to NULL and as everyone knows.. When you try to dereference
a NULL pointer (or a pointer to memory that doesn't belong to you) what you get
is a nice pleasent core dump.


I'd suggest making a different variable for iterating through the list.

~Kender

=====
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/L/C/O d-(+) s++:+ a-- C+++$>++++ UBLS++++$ 
P+++(--)$ L++>+++ E--- W+>++$ N !o K? w(--) !O 
M- !V PS+ PE(++) Y+ PGP->+ t- 5 X+() R(+) tv+@ 
b++(+++) !DI+++ D G(-) e>+++$ h---() r+++ y+++
------END GEEK CODE BLOCK------

__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

Reply via email to