This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 110c. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2023-02-07


1438. Non-dereference use of invalid pointers

Section: _N4885_6.7.5.5.4  [basic.stc.dynamic.safety]     Status: CD3     Submitter: Anthony Williams     Date: 2012-01-03

[Moved to DR at the October, 2012 meeting.]

The current Standard says that any use of an invalid pointer value produces undefined behavior (6.7.5.5.3 [basic.stc.dynamic.deallocation] paragraph 4). This includes not only dereferencing the pointer but even just fetching its value. The reason for this draconian restriction is that some architectures in the past used dedicated address registers for pointer loads and stores and they could fault if, for example, a segment number in a pointer was not currently mapped.

It is not clear whether such restrictions are necessary with architectures currently in use or reasonably foreseen. This should be investigated to see if the restriction can be loosened to apply only to dereferencing the pointer.

Proposed resolution (February, 2012):

Change 6.7.5.5.3 [basic.stc.dynamic.deallocation] paragraph 4 as follows:

If the argument given to a deallocation function in the standard library is a pointer that is not the null pointer value (7.3.12 [conv.ptr]), the deallocation function shall deallocate the storage referenced by the pointer, rendering invalid all pointers referring to any part of the deallocated storage. The effect of using an invalid pointer value (including passing it to a deallocation function) is undefined Indirection through an invalid pointer value and passing an invalid pointer value to a deallocation function have undefined behavior. Any other use of an invalid pointer value has implementation-defined behavior. [Footnote: On some Some implementations, it might define that copying an invalid pointer value causes a system-generated runtime fault. —end footnote]