RFR: 8305650: os::lasterror incorrectly truncates buffer in os_windows.cpp
David Holmes
dholmes at openjdk.org
Thu Apr 6 05:56:13 UTC 2023
On Thu, 6 Apr 2023 05:38:13 GMT, Julian Waters <jwaters at openjdk.org> wrote:
>> The actual characters of a `n` length string occupy `buf[0]` to `buf[n-1]`, with the terminating nul at `buf[n]`.
>
> I understand that that would be the case if n = strlen(s) + 1, but here it's only n = strlen(s). Am I missing something?
char* s = "A";
int n = strlen(s); // n == 1
char buf[2];
strncpy(buf, s, n) // copies 1 character: buf[0] == 'A'
buf[n] = '\0`; // buf[1] == '0`
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13350#discussion_r1159310465
More information about the hotspot-runtime-dev
mailing list