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

Julian Waters jwaters at openjdk.org
Thu Apr 6 06:35:23 UTC 2023


On Thu, 6 Apr 2023 06:00:44 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

>> 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`
>
>> 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?
> 
> Array addressing via [] is zero based. See Davids example. For "ABC" A is index 0, C is 2, \0 is 3.

*facepalm

I completely forgot about array indexing. Sorry for all the trouble

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

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


More information about the hotspot-runtime-dev mailing list