-
-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vsprintf_s() should return 0 for "vsprintf_s: len exceeds dmax" #45
Comments
Yes, but in this case I (and all others) think the standard made an error. I'll have to check the history of that. The revision and rationale for this change is: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1141.pdf I'll add a doc note that the spec is most likely wrong on this one, and keep the -1. |
See GH #45. In this case I (and all others) think the standard made an error. All existing implementations do return -1 on errors, all similar functions do return -1. The revision and rationale for this change is: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1141.pdf keeping count += sprintf(buf + count, format_string, args); valid, when no encoding errors can occur. google site:www.open-std.org vsprintf_s. Even Microsoft itself, who changed this behaviour in the standard with n1141, changed it later back to return -1 consistently. Document the deviation, and test it against msvcrt.
See GH #45. In this case I (and all others) think the standard made an error. All existing implementations do return -1 on errors, all similar functions do return -1. The revision and rationale for this change is: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1141.pdf keeping count += sprintf(buf + count, format_string, args); valid, when no encoding errors can occur. google site:www.open-std.org vsprintf_s. Even Microsoft itself, who changed this behaviour in the standard with n1141, changed it later back to return -1 consistently. Document the deviation, and test it against msvcrt.
According to standard:
If no runtime-constraint violation occurred, the vsprintf_s function returns the number of characters written in the array, not counting the terminating null character. If an encoding error occurred, vsprintf_s returns a negative value. If any other runtime-constraint violation occurred, vsprintf_s returns zero.
Scenario "vsprintf_s: len exceeds dmax" is run-time constraint violation & not encoding error so the return value should be 0.
Link to the code instance: https://github.com/rurban/safeclib/blob/master/src/str/vsprintf_s.c#L147
The text was updated successfully, but these errors were encountered: