Title
Uninitialized trailing characters in string initialization
Status
cd2
Section
9.4.3 [dcl.init.string]
Submitter
James Kanze

Created on 2008-10-26.00:00:00 last changed 171 months ago

Messages

Date: 2009-10-15.00:00:00

[Voted into WP at October, 2009 meeting.]

Date: 2009-09-15.00:00:00

Proposed resolution (September, 2009):

Add a new paragraph following 9.4.3 [dcl.init.string] paragraph 2:

There shall not be more initializers than there are array elements. [Example:

  char cv[4] = "asdf";    // error

is ill-formed since there is no space for the implied trailing '\0'. —end example]

If there are fewer initializers than there are array elements, then each element not explicitly initialized shall be zero-initialized (9.4 [dcl.init]).

Date: 2009-03-23.00:00:00

The current specification of string initialization in 9.4.3 [dcl.init.string] leaves uninitialized all characters following the terminating '\0' of a character array with automatic storage duration. This is different from C99, in which string initialization is handled like aggregate initialization and all trailing characters are zeroed (6.7.8 paragraph 21).

(See also issue 694, in which we are considering following C99 in a somewhat similar case of zero-initializing trailing data.)

History
Date User Action Args
2010-03-29 00:00:00adminsetstatus: dr -> cd2
2009-11-08 00:00:00adminsetmessages: + msg2457
2009-11-08 00:00:00adminsetstatus: tentatively ready -> dr
2009-09-29 00:00:00adminsetmessages: + msg2298
2009-09-29 00:00:00adminsetstatus: drafting -> tentatively ready
2009-08-03 00:00:00adminsetstatus: open -> drafting
2008-10-26 00:00:00admincreate