[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: value of dangling pointer
From: |
Igor Khavkine |
Subject: |
Re: value of dangling pointer |
Date: |
Tue, 31 Jul 2001 19:17:45 -0400 |
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?
You have to remember that the function free() cannot modify the value
of its argument (nm->name) since it's only passed by value. So before
or after nm->name has the same value, and so can be compared to
nm->canon since neither of them has been modified.
Igor