**Submitter:**Fred J. Tydeman

**Submission Date:** 2020-02-23

**Document:** WG14 N2495

**Title:** N2495: snprintf

**Reference Documents:** N2478

Summary

snprintf has ambiguous or contradictorary statements. In the returns section (paragraph 3) is an "if and only if" statement. If the second part of that is false, then the entire first part must be false. That means, if n is less than the return value [second part false], then the output is NOT complete and the output is NOT null terminated [first part false]. However, the description (paragraph 2) says that the output is null terminated for this case.

Most implementations do null-terminate the output for small n, but I have found at least one implementation that does not null-terminate the output when n is less than the return value.

Technical Corrigendum:

In 7.21.6.5 The snprintf function: Change in paragraph 3 (Returns):

Thus, the null-terminated output has been completely written if and only if the returned value is nonnegative and less than n.

to:

If the returned value is nonnegative the output is null-terminated. The output has been completely written if and only if the returned value is nonnegative and less than n.

The same fix needs to also be applied to

- 7.21.6.12 The vsnprintf function
- 7.22.1.3 The strfromd, strfromf, and strfroml functions
- 7.22.1.4 The strfromdN functions
- K.3.5.3.5 The snprintf_s function
- K.3.5.3.12 The vsnprintf_s function
- K.3.9.1.3 The snwprintf_s function
- K.3.9.1.8 The vsnwprintf_s function