RFR(XS): 8214707: Prevent GCC 8 from reporting error in ClassLoader::file_name_for_class_name()

Thomas Stüfe thomas.stuefe at gmail.com
Fri Dec 7 16:08:42 UTC 2018


On Fri, Dec 7, 2018 at 11:46 AM David Holmes <david.holmes at oracle.com> wrote:
>
> On 7/12/2018 7:43 pm, Thomas Stüfe wrote: [-Werror=sizeof-pointer-memaccess]
> > On Fri, Dec 7, 2018 at 2:09 AM David Holmes <david.holmes at oracle.com> wrote:
> >>
> >> +1
> >>
> >> Annoying to have to workaround a buggy compiler though. :(
> >>
> >
> > I do not think this is a compiler bug but a usage error which in this
> > case was harmless.
> >
> > I think the compiler warning is correct.
>
> We replaced the third argument to strncpy with a local variable that has
> the exact same value as what was warned about. In other words we passed
> the exact same value - yet one case got a warning and the other did not.
>
> Either the value is wrong or the value is right.

You just hide the usage error enough from the compiler that it stops
caring. If I look at the error message:

"‘sizeof’ in ‘char* strncpy(char*, const char*, size_t)’ call __is the
same expression as the source; did you mean to use the size of the
destination__?"

it says right there that it assumes you make an error in specifying
the source size, not the destination length.

Assuming that the purpose of strncpy() was to prevent overwriting the
destination buffer (as snprintf etc), this warning makes sense.

..Thomas


More information about the hotspot-runtime-dev mailing list