RFR: 8305650: os::lasterror incorrectly truncates buffer in os_windows.cpp

Julian Waters jwaters at openjdk.org
Thu Apr 6 05:41:14 UTC 2023


On Thu, 6 Apr 2023 05:31:40 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> I don't quite follow, strlen only returns the length of the string _without_ the null terminating character, so the string's actual character data does indeed occupy buf[0] to buf[n] (since n = strlen(s)), meaning that the null terminator would be at n + 1. When strncpy is called later on it always reaches the count n before it reaches the null character, so the string that was copied is never null terminated, meaning that nulling buf[n] would actually erroneously discard the last character in the buffer
>
> 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?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13350#discussion_r1159302749


More information about the hotspot-runtime-dev mailing list