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).
Btw, is the cast necessary?  realloc() returns void*, after all...


Segher

Reply via email to