RFR: 8296812: sprintf is deprecated in Xcode 14 [v6]
Thomas Stuefe
stuefe at openjdk.org
Wed Nov 16 09:10:01 UTC 2022
On Wed, 16 Nov 2022 05:45:34 GMT, Xue-Lei Andrew Fan <xuelei at openjdk.org> wrote:
>> A result of -1 only occurs for an encoding error. An encoding error is only
>> possible with multi-byte / wide characters. (See the definition of "encoding
>> error" in C99 7.19.3/14.) We don't use those, so there won't be any encoding
>> errors, so our uses of snprintf never return -1.
>
> Updated to use the result from `os::snprtinf` in the new commit.
> A result of -1 only occurs for an encoding error. An encoding error is only possible with multi-byte / wide characters. (See the definition of "encoding error" in C99 7.19.3/14.) We don't use those, so there won't be any encoding errors, so our uses of snprintf never return -1.
Hi @kimbarrett,
I am not sure this was true. E.g. https://stackoverflow.com/questions/65334245/what-is-an-encoding-error-for-sprintf-that-should-return-1 cites some cases where snprintf returns -1 that have nothing to do with multibyte strings. Also, size=0 would return -1 according to SUSv2.
Note glibc differs and returns the number of chars it *would* have printed. Which is also dangerous in a different way. If you use that number to update the position, the position is not limited to buffer boundaries. So, I think the result of os::snprintf should not be used to update buffer position, at least not without checking.
-------------
PR: https://git.openjdk.org/jdk/pull/11115
More information about the hotspot-dev
mailing list