talloc()

Steve Langasek vorlon at netexpress.net
Mon Aug 14 13:42:20 GMT 2000


On Mon, 14 Aug 2000, Luke Kenneth Casson Leighton wrote:

> On Mon, 14 Aug 2000, Luke Kenneth Casson Leighton wrote:

> > On Fri, 11 Aug 2000, Andrew Tridgell wrote:

> > > Luke,

> > > nope, that makes no sense. There is no allocated area when you ask for
> > > zero bytes.

> > zero bytes returns NULL?

> ... ah, you mean that when a talloc of zero is requested, no advance is
> made on the pointer.

> ... then, an advance of 8 bytes should be made, filled with
> 0xdeadbeefbeefdead and then address+4 returned.

If the code requests 0 bytes to be allocated and then writes to the pointer
that was returned, there's no guarantee that it won't be writing more than 4
bytes.  It may overwrite other chunks of allocated memory, and possibly cause
problems elsewhere.  Difficult to track.

If, on the other hand, talloc(0) returns a *pointer* with the value 
0xdeadbeef, the first time the code tries to write to that pointer, you get a
segfault.  Much handier for debugging.

Steve Langasek
postmodern programmer





More information about the samba-technical mailing list