[12] RFR: 8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
Kim Barrett
kim.barrett at oracle.com
Tue Dec 11 01:27:24 UTC 2018
> On Dec 10, 2018, at 1:57 PM, Simon Tooke <stooke at redhat.com> wrote:
>
> This small patch fixes some simple warnings in Hotspot code, found by
> GCC 8.1
>
> Essentially, any code sequence of the pattern
>
> int l = strlen(somestring)
> char* buffer = malloc(l + 1)
> strncpy(buffer, somestring, l)
> buffer[l] = 0
>
> is replaced by
>
> int len = strlen(somestring)
> char* buffer = malloc(len + 1)
> strncpy(buffer, somestring, len + 1)
>
> For xmlstream.cpp, this is actually a small inefficiency, as the null
> byte is immediately overwritten; but it makes GCC happy.
Why not just call strcpy, rather than strncpy, since the size is obviously sufficient.
> Bug: https://bugs.openjdk.java.net/browse/JDK-8214777
> Webrev:
> http://cr.openjdk.java.net/~sgehwolf/webrevs/stooke/JDK-8214777/02/webrev/
More information about the hotspot-runtime-dev
mailing list