understood.
Thanks

On Thu, Apr 14, 2011 at 10:44 AM, Tim Van Holder
<[email protected]>wrote:

> That man page means that if you ask for 0 bytes (0 * sizeof(...)),
> either it gives NULL back or a pointer to 0 bytes of allocated bytes (so
> that it's a valid pointer to pass to free, but nothing else).
> You'll probably find similar wording in "man malloc".
>
> Using that pointer for actual data means you were always overwriting
> unallocated memory, leading to undefined behaviour (with segfaults being
> very likely).
>
> On 14/04/2011 10:17, Emanuele Placidi wrote:
> > Well, calloc accepts "nmemb" with 0 and it is used to alloc a single
> > chunk of memory sized "size"
> > From man calloc:
> > void *calloc(size_t nmemb, size_t size);
> > ....
> >  If nmemb or size is 0, then calloc() returns either NULL, or a unique
> > pointer value that can later be successfully passed to free().
> > .....
> >
> > Anyway thanks for your help, can you send me the valgrind output?.
> > Regards
> >    Zad
> > On Thu, Apr 14, 2011 at 3:11 AM, Noam Postavsky
> > <[email protected] <mailto:[email protected]>>
> > wrote:
> >
> >     Emanuele Placidi <[email protected]
> >     <mailto:[email protected]>> writes:
> >
> >     > Hi,
> >     >  I would to point out a strange behaviour when storing in a
> >     structure an
> >     > xmlChar pointer returned by xmlGetProp().
> >     > In attach there is a very simple code which sig faults when
> >     compiled with gcc
> >
> >     Well I didn't get a segfault on my machine using gcc 4.5.2 and
> libxml2
> >     2.7.8, but valgrind did indicate many errors. For instance line 369:
> >
> >      reg=calloc(0,sizeof(struct register_desc));
> >
> >     You are allocating memory for 0 register_desc structs here. If this
> code
> >     ever worked it was only by accident.
>
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to