Re: [xml] xml2 2.7.8 + gcc 4.5.2 unpredictable behaviour
- From: Emanuele Placidi <emanuele placidi gmail com>
- To: xml gnome org
- Subject: Re: [xml] xml2 2.7.8 + gcc 4.5.2 unpredictable behaviour
- Date: Thu, 14 Apr 2011 10:56:48 +0200
understood.
Thanks
On Thu, Apr 14, 2011 at 10:44 AM, Tim Van Holder
<tim van holder telenet be> 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
> <npostavs users sourceforge net <mailto:npostavs users sourceforge net>>
> <mailto:
emanuele placidi gmail com>> 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.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]