[12] RFR: 8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
David Holmes
david.holmes at oracle.com
Mon Dec 10 21:47:51 UTC 2018
Hi Simon,
On 11/12/2018 4:57 am, Simon Tooke wrote:
> This small patch fixes some simple warnings in Hotspot code, found by
> GCC 8.1
I hate having to change code just to silence faulty tools :(
> 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.
For xmlstream and src/hotspot/share/runtime/arguments.cpp I can't
convince myself that the change is always correct, because (taking the
arguments example) I'm not sure what "pos-tail" evaluates to and exactly
what the string might look like, and so whether we're guaranteed to hit
a Nul-terminator in that case.
if(tail != NULL) {
const char* pos = strchr(tail, '=');
size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
! char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1,
mtArguments), tail, len + 1);
Aside: note this bug is currently targeted to 13, if it may be pushed to
12 it needs to be updated first.
Thanks,
David
-----
>
> 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