Authors: Joseph Myers
Date: 2025-03-18
Submitted against: C23
Status: Open
Cross-references: 1004
Each function in the printf and scanf family has its own
Returns specification that describes error cases and corresponding
return values as well as the return value on success (the error cases
sometimes depend on the specific function from the family; for
example, some kinds of errors can only occur for the functions using
files, not those using strings).
When error cases were added to fprintf, fscanf, fwprintf and
fwscanf for unsupported specific width length modifiers, no
corresponding changes were made to the Returns specification for
the other functions in those families, so failing to give those other
functions a corresponding error case (and leaving them with implicit
undefined behavior in this case). It seems clear that all functions
in these families should have corresponding error handling.
This is related to but separate from issue 1004, which
concerns the classification of such errors from scanf functions.
Also, the descriptions for printf functions refer to "specified
width length modifier" but those for scanf functions refer to
"specific width length modifier", with no apparent reason for the
inconsistent terminology.
All these changes are to the Returns specification of their respective functions, and all subclause numbers are in C23.
First, for consistency of terminology, make the following changes.
In 7.23.6.2 (The fprintf function), change:
The
fprintffunction returns the number of characters transmitted, or a negative value if an output or encoding error occurred or if the implementation does not support aspecifiedspecific width length modifier.
In 7.31.2.2 (The fwprintf function), change:
The
fwprintffunction returns the number of wide characters transmitted, or a negative value if an output or encoding error occurred or if the implementation does not support aspecifiedspecific width length modifier.
Then amend the other functions in these families as follows.
In each of 7.23.6.4 (The printf function), 7.23.6.6 (The snprintf
function), 7.23.6.7 (The sprintf function), 7.23.6.9 (The vfprintf
function), 7.23.6.11 (The vprintf function), 7.23.6.13 (The
vsnprintf function), 7.23.6.14 (The vsprintf) function), 7.31.2.4
(The swprintf function), 7.31.2.6 (The vfwprintf function),
7.31.2.8 (The vswprintf function), 7.31.2.10 (The vwprintf
function), 7.31.2.12 (The wprintf function), K.3.5.4.7 (The
sprintf_s function), K.3.5.4.14 (The vsprintf_s function),
K.3.9.2.4 (The swprintf_s function), and K.3.9.2.9 (The
vswprintf_s function), change:
... encoding error occurred or if the implementation does not support a specific width length modifier ...
(Some of these functions also refer to output errors earlier in the
amended text; others, where the output is to a string rather than a
file, do not. In the case of swprintf,vswprintf, swprintf_s,
and vswprintf_s, the amended text is followed by another error case
in the same sentence; in the case of sprintf_s, vsprintf_s,
swprintf_s, and vswprintf_s, a description of the return value
appears after the amended text.)
In each of 7.23.6.5 (The scanf function), 7.23.6.8 (The sscanf
function), 7.23.6.10 (The vfscanf function), 7.23.6.12 (The vscanf
function), 7.23.6.15 (The vsscanf function), 7.31.2.5 (The swscanf
function), 7.31.2.7 (The vfwscanf function), 7.31.2.9 (The
vswscanf function), 7.31.2.11 (The vwscanf function), 7.31.2.13
(The wscanf function), K.3.5.4.3 (The fscanf_s function),
K.3.5.4.5 (The scanf_s function), K.3.5.4.8 (The sscanf_s
function), K.3.5.4.10 (The vfscanf_s function), K.3.5.4.12 (The
vscanf_s function), K.3.5.4.15 (The vsscanf_s function), K.3.9.2.2
(The fwscanf_s function), K.3.9.2.5 (The swscanf_s function),
K.3.9.2.7 (The vfwscanf_s function), K.3.9.2.10 (The vswscanf_s
function), K.3.9.2.12 (The vwscanf_s function), and K.3.9.2.14 (The
wscanf_s function), change:
... in the event of an early matching failure or if the implementation does not support a specific width length modifier.
In each of K.3.5.4.2 (The fprintf_s function), K.3.5.4.4 (The
printf_s function), K.3.5.4.6 (The snprintf_s function), K.3.5.4.9
(The vfprintf_s function), K.3.5.4.11 (The vprintf_s function),
K.3.5.4.13 (The vsnprintf_s function), K.3.9.2.1 (The fwprintf_s
function), K.3.9.2.3 (The snwprintf_s function), K.3.9.2.6 (The
vfwprintf_s function), K.3.9.2.8 (The vsnwprintf_s function),
K.3.9.2.11 (The vwprintf_s function), and K.3.9.2.13 (The
wprintf_s function), change:
... runtime-constraint violation occurred or if the implementation does not support a specific width length modifier.
Comment from Issues list maintainer on 2025-09-01:
This issue was discussed at the August 2025 (Brno) meeting of WG14 but
without voting on specific wording. For printf functions, Alejandro
Colomar plans to write a paper addressing this issue. For scanf
functions, new wording suggested for issue 1004 would
also address this issue.