RFR: 8354453: Don't strcpy in os::strdup, use memcpy instead [v2]

Johan Sjölen jsjolen at openjdk.org
Fri Apr 25 11:10:05 UTC 2025


On Thu, 24 Apr 2025 08:42:40 GMT, Anton Artemov <duke at openjdk.org> wrote:

>> Use memcpy instead of strcpy in os::strdup, 1 string pass fewer.
>> 
>> Tested in tiers 1-3, all tests pass.
>
> Anton Artemov has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:
> 
>  - Merge remote-tracking branch 'origin/master' into JDK-8354453
>  - 8354453: Don't strcpy in os::strdup, use memcpy instead

src/hotspot/share/runtime/os.cpp line 600:

> 598:   if (dup_str == nullptr) return nullptr;
> 599:   memcpy(dup_str, str, size);
> 600:   *(dup_str + size) = '\0';

Just `memcpy(dup_str, str, size + 1)` ?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24651#discussion_r2060032059


More information about the hotspot-runtime-dev mailing list