At 1:21 PM +0100 2/17/02, Segher Boessenkool wrote:
>Steve Fink wrote:
>>
>>  > -      key->keys = (KEY_PAIR*)realloc(key->keys,sizeof(KEY_PAIR)*size);
>>  > +      key->keys = (KEY_PAIR**)realloc(key->keys,sizeof(KEY_PAIR)*size);
>>
>>  That seems rather suspicious. I don't know anything about the KEY_PAIR
>>  type, but allocating a chunk of memory big enough to fit N structures
>>  and then using it as an array of pointers to individual structures...
>>  well, something's fishy.
>
>That's why it's safer to write
>
>p = realloc(p, N * sizeof(*p));
>
>whenever possible (that is, if p has correct type).

Or mem_realloc to use the builtin memory pools, but good enough.

>Btw, is the cast necessary?  realloc() returns void*, after all...

I think I'd rather we did have the cast in there. If nothing else, 
it'll help us note where we've cast incorrectly and, while that might 
just be an error in the casting, it might also indicate an error in 
the logic.
-- 
                                         Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                       teddy bears get drunk

Reply via email to