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:
*printf functions, a conversion specification of s
with a precision of zero for example %.s.strftime and wcsftime.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.
Modify N3886 7.24.6.2 (The fprintf function) paragraph 8:
If no
llength 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
llength modifier is present, the argument shall be a pointer to storage ofwchar_ttype. Wide characters from the storage are converted to multibyte characters (each as if by a call to thewcrtombfunction, with the conversion state described by anmbstate_tobject 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
llength 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 thembrtowcfunction, with the conversion state described by anmbstate_tobject 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
llength modifier is present, the argument shall be a pointer to storage ofwchar_ttype. 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
strftimefunction places characters into the array pointed to bysas controlled by the string pointed to byformat. The format shall be a multibyte character sequence, beginning and ending in its initial shift state. Theformatstring consists of zero or more conversion specifiers and ordinary multibyte characters. A conversion specifier consists of a%character, possibly followed by anEorOmodifier 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 thanmaxsizecharacters are placed into the array. Ifmaxsizeis zero,smay 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
nelements will be modified in the array pointed to bypwcs. If copying takes place between objects that overlap, the behavior is undefined. Ifpwcsis a null pointer value, the behavior is undefined.
Modify N3886 7.25.9.3 (The wcstombs function) paragraph 3:
No more than
nbytes will be modified in the array pointed to bys. If copying takes place between objects that overlap, the behavior is undefined. Ifsis a null pointer value, the behavior is undefined.