RFR: 8296812: sprintf is deprecated in Xcode 14 [v6]
Kim Barrett
kbarrett at openjdk.org
Wed Nov 16 04:58:19 UTC 2022
On Tue, 15 Nov 2022 08:31:10 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
>> src/hotspot/os/bsd/attachListener_bsd.cpp line 294:
>>
>>> 292: (atoi(buf) != ATTACH_PROTOCOL_VER)) {
>>> 293: char msg[32];
>>> 294: os::snprintf(msg, sizeof(msg), "%d\n", ATTACH_ERROR_BADVERSION);
>>
>> Rather than using `strlen(msg)` in the next line, use the result from `os::snprintf`.
>
> The problem with using the return value of os::snprintf() is that we need to handle the -1 case to prevent the position from running backward. Might be better to use stringStream instead, which should handle the -1 case transparently.
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.
-------------
PR: https://git.openjdk.org/jdk/pull/11115
More information about the hotspot-dev
mailing list