Bugzilla – Bug 1084639
GCC 8: libX11 build fails
Last modified: 2018-03-15 11:02:53 UTC
Build the package with GCC 8, there's error:
[ 108s] /usr/include/bits/string_fortified.h:90:10: error: '__builtin_strcpy' forming offset 2 is out of the bounds [0, 1] [-Werror=array-bounds]
Please build the project as follows to reproduce the issue:
osc build --alternative-project=openSUSE:Factory:Staging:Gcc7
Confirmed. The full error is:
> In file included from /usr/include/string.h:494,
> from /usr/include/X11/Xos.h:62,
> from imLcIm.c:42:
> In function 'strcpy',
> inlined from '_XimWriteCachedDefaultTree' at imLcIm.c:479:5,
> inlined from '_XimCreateDefaultTree' at imLcIm.c:616:2,
> inlined from '_XimLocalOpenIM' at imLcIm.c:700:5:
> /usr/include/bits/string_fortified.h:90:10: error: '__builtin_strcpy'
> forming offset 2 is out of the bounds [0, 1] [-Werror=array-bounds]
> return __builtin___strcpy_chk (__dest, __src, __bos (__dest));
The offending line is:
> imLcIm.c:479: strcpy (m->fname+strlen(name)+1, encoding);
The `m` is `struct _XimCacheStruct*` and the `fname` field is `char fname`.
So gcc is complaining that we are going to write past this 1-element array. The allocated memory for `m` is actually big enough to store the full fname plus encoding behind the `_XimCacheStruct` struct, so it works.
No idea why the original author decided that `char fname` is a good way to declare it. I'll change it to something that doesn't trigger the warning.
Created attachment 763761 [details]
Use flexible array member instead of fake size.
Fix for the build error. Also sent to xorg-devel:
Thanks, Michal! Could you do a SR for X11:XOrg/libX11, so we can close the bugreport?
(In reply to Stefan Dirsch from comment #3)
> Thanks, Michal! Could you do a SR for X11:XOrg/libX11, so we can close the
OMG. It was already queued. Thanks!