Re: C Standard Regarding Null Pointer Dereferencing
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Thu, 22 Jul 2010 10:09:53 +0100
Shao Miller wrote:
On Jul 21, 8:44 pm, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:Open and shut case.Obviously it "feels" like it should be undefined behaviour, since
we've all been trying to avoid the act of a "null pointer dereference"
for a long time.
See 6.5.3.2.
"The unary * operator denotes indirection. If the operand points to a function, the result is a function designator; if it points to an object, the result is an lvalue designating the object. If the operand has type ‘‘pointer to type’’, the result has type ‘‘type’’. If an
invalid value has been assigned to the pointer, the behavior of the unary * operator is undefined."
NULL is an invalid value - it is guaranteed not to point to any object or function. (See 6.3.2.3.)
Therefore, using * on a null pointer invokes UB.
<snip>
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
.
- Follow-Ups:
- Re: C Standard Regarding Null Pointer Dereferencing
- From: Shao Miller
- Re: C Standard Regarding Null Pointer Dereferencing
- References:
- C Standard Regarding Null Pointer Dereferencing
- From: Shao Miller
- Re: C Standard Regarding Null Pointer Dereferencing
- From: Richard Heathfield
- Re: C Standard Regarding Null Pointer Dereferencing
- From: Shao Miller
- Re: C Standard Regarding Null Pointer Dereferencing
- From: Richard Heathfield
- Re: C Standard Regarding Null Pointer Dereferencing
- From: Shao Miller
- C Standard Regarding Null Pointer Dereferencing
- Prev by Date: Re: Reading little-endian data from a file in a portable manner
- Next by Date: Re: Reading little-endian data from a file in a portable manner
- Previous by thread: Re: C Standard Regarding Null Pointer Dereferencing
- Next by thread: Re: C Standard Regarding Null Pointer Dereferencing
- Index(es):
Relevant Pages
|