Issue 1109: N3322 and N3466 overlooked a few cases

Authors: Jay Ghiron
Date: 2026-09-15
Submitted against: C2Y (N3886 draft)
Status: Open

The proposals N3322 and N3466 allowed null pointers to many library functions when no elements are accessed. However, there were a few cases that were not mentioned in either proposal:

  1. In any of the *printf functions, a conversion specification of s with a precision of zero for example %.s.
  2. strftime and wcsftime.
  3. mbstowcs and wcstombs.

The first two should probably be valid, the third is already defined by POSIX so the behavior should remain undefined or the POSIX behavior should be adopted.

Suggested correction

Modify N3886 7.24.6.2 (The fprintf function) paragraph 8:

If no l length modifier is present, the argument shall be a pointer to storage of character type. Characters from the storage are written up to (but not including) the terminating null character. If the precision is specified, no more than that many bytes are written. If the precision is not specified or is greater than the size of the storage, the storage shall contain a null character. If the precision is specified as zero, the argument may be a null pointer.

If an l length modifier is present, the argument shall be a pointer to storage of wchar_t type. Wide characters from the storage are converted to multibyte characters (each as if by a call to the wcrtomb function, with the conversion state described by an mbstate_t object initialized to zero before the first wide character is converted) up to and including a terminating null wide character. The resulting multibyte characters are written up to (but not including) the terminating null character (byte). If no precision is specified, the storage shall contain a null wide character. If a precision is specified, no more than that many bytes are written (including shift sequences, if any), and the storage shall contain a null wide character if, to equal the multibyte character sequence length given by the precision, the function would need to access a wide character one past the end of the array. In no case is a partial multibyte character written. If the precision is specified as zero, the argument may be a null pointer.

Modify N3886 7.33.2.2 (The fwprintf function) paragraph 8:

If no l length modifier is present, the argument shall be a pointer to storage of character type containing a multibyte character sequence beginning in the initial shift state. Characters from the storage are converted as if by repeated calls to the mbrtowc function, with the conversion state described by an mbstate_t object initialized to zero before the first multibyte character is converted, and written up to (but not including) the terminating null wide character. If the precision is specified, no more than that many wide characters are written. If the precision is not specified or is greater than the size of the converted storage, the converted storage shall contain a null wide character. If the precision is specified as zero, the argument may be a null pointer.

If an l length modifier is present, the argument shall be a pointer to storage of wchar_t type. Wide characters from the storage are written up to (but not including) a terminating null wide character. If the precision is specified, no more than that many wide characters are written. If the precision is not specified or is greater than the size of the array, the storage shall contain a null wide character. If the precision is specified as zero, the argument may be a null pointer.

Modify N3886 7.31.3.6 (The strftime function) paragraph 2:

The strftime function places characters into the array pointed to by s as controlled by the string pointed to by format. The format shall be a multibyte character sequence, beginning and ending in its initial shift state. The format string consists of zero or more conversion specifiers and ordinary multibyte characters. A conversion specifier consists of a % character, possibly followed by an E or O modifier character (described later), followed by a character that determines the behavior of the conversion specifier. All ordinary multibyte characters (including the terminating null character) are copied unchanged into the array. If copying takes place between objects that overlap, the behavior is undefined. No more than maxsize characters are placed into the array. If maxsize is zero, s may be a null pointer.

Note: wcsftime refers to strftime directly so no wording adjustment is needed there.

Modify N3886 7.25.9.2 (The mbstowcs function) paragraph 3:

No more than n elements will be modified in the array pointed to by pwcs. If copying takes place between objects that overlap, the behavior is undefined. If pwcs is a null pointer value, the behavior is undefined.

Modify N3886 7.25.9.3 (The wcstombs function) paragraph 3:

No more than n bytes will be modified in the array pointed to by s. If copying takes place between objects that overlap, the behavior is undefined. If s is a null pointer value, the behavior is undefined.