[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: value of dangling pointer

From: Adam Olsen
Subject: Re: value of dangling pointer
Date: Tue, 31 Jul 2001 23:19:34 +0000
User-agent: Mutt/1.3.18i

On Wed, Aug 01, 2001 at 01:47:27AM +0300, Kalle Olavi Niemitalo wrote:
> hostmux/mux.c (free_name) does this:
>   free ((char *)nm->name);
>   if (nm->name != nm->canon)
>     free ((char *)nm->canon);
> However, according to the C99 N869 draft, "The value of a pointer
> that refers to freed space is indeterminate" (7.20.3 [#1]), which
> causes undefined behavior if used (3.18 [#1]).  IIRC, the final
> standard has a similar rule.
> Does some undocumented GCC extension make such use valid, or
> should the two statements be swapped?

I think that because C uses pass-by-value, there's no way for the
pointer to be changed and thus invalidate the comparison.  But I also
think it's implimentation specific and thus they should be swapped on
principle if nothing else.

Hmm.  I'm not sure about garbage collectors though, or how C-compliant
they are.  It may be perfectly valid for free to clear the pointer
itself.. (or only one pointer, since clearing both would work fine.)

IMHO of course.  I've never read the C spec(s) :)

Adam Olsen, aka Rhamphoryncus

reply via email to

[Prev in Thread] Current Thread [Next in Thread]