On 10/23/07, Michael Schippling <[EMAIL PROTECTED]> wrote:
> If "serial_source" has been typedefed to be a pointer,
> which is what the subsequent usage tends to indicate,
> then this _should_ allocate and init a block of whatever
> rather than just a pointer. If that is the case then it
> seems to be a poor naming choice. You'll have to chase
> the dragon further up the tree to see what it really is...

I'll point out that if you write "x = malloc(sizeof *x)", you're
guaranteed to get something of the size of whatever x is declared to
point to, irrespective of any changes anywhere else in the program
(ok, making x a non-pointer will cause a compile-time error). Seems:
a) pretty clear, b) pretty reliable.

David Gay


>
> MS
>
> Daniel Widyanto wrote:
> > Hi all,
> >
> > I'm currently debugging strange error in serial forwarder (c version,
> > TinyOS 2.0.1), and I found this :
> > //////////////////
> > serialsource.c:273:
> >   serial_source src = malloc(sizeof *src);
> >   if (src)
> >  {
> >     memset(src, 0, sizeof *src);
> >     src->fd = fd;
> >     src->non_blocking = non_blocking;
> >     src->message = message;
> >     src->send.seqno = 37;
> >
> >     return src;
> >   }
> > ///////////////////
> >
> > I think malloc(sizeof *src) will return pointer to 4-bytes allocated heap,
> > instead of pointer to sizeof(struct serial_source). So, src->non_blocking,
> > src->message, and src->send.seqno will point to memory that's not
> > belonging to this program.
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to