Submitter:Fred J. Tydeman
Submission Date: 2020-02-23
Document: WG14 N2495
Title: N2495: snprintf
Reference Documents: N2478
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.
In 220.127.116.11 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.
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