Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

xcursor: strncpy truncation warning with GCC 10 on s390x #2018

Closed
khardix opened this issue Feb 4, 2020 · 0 comments · Fixed by #2768
Closed

xcursor: strncpy truncation warning with GCC 10 on s390x #2018

khardix opened this issue Feb 4, 2020 · 0 comments · Fixed by #2768

Comments

@khardix
Copy link
Contributor

khardix commented Feb 4, 2020

When building 0.10.0 for Fedora (Rawhide, currently with GCC 10), there is a strncpy warning in xcursor/xcursor.c:

In file included from /usr/include/string.h:495,
                 from ../xcursor/xcursor.c:30:
In function 'strncpy',
    inlined from '_XcursorAddPathElt' at ../xcursor/xcursor.c:657:5,
    inlined from '_XcursorBuildFullname' at ../xcursor/xcursor.c:731:5,
    inlined from 'XcursorScanTheme' at ../xcursor/xcursor.c:820:13:
/usr/include/bits/string_fortified.h:106:10: error: '__builtin_strncpy' output truncated before terminating nul copying 7 bytes from a string of the same length [-Werror=stringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'strncpy',
    inlined from '_XcursorAddPathElt' at ../xcursor/xcursor.c:657:5,
    inlined from '_XcursorBuildFullname' at ../xcursor/xcursor.c:731:5,
    inlined from 'xcursor_load_theme' at ../xcursor/xcursor.c:959:10:
/usr/include/bits/string_fortified.h:106:10: error: '__builtin_strncpy' output truncated before terminating nul copying 7 bytes from a string of the same length [-Werror=stringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Thanks to -Werror, this aborts the build.


I checked the code around the specified lines, and the \0 is currently added explicitly:

wlroots/xcursor/xcursor.c

Lines 657 to 658 in f2943bd

strncpy (path + pathlen, elt, len);
path[pathlen + len] = '\0';

Because this only manifests on one architecture, and the warning is mitigated on the very next line, I'm inclined to blame GCC and consider this a false positive. Nevertheless, if we want to keep -Werror on, the offending code probably have to be changed.

For the time being, I will work around this by disabling the -Werror flag.

slyon added a commit to slyon/wlroots that referenced this issue Mar 3, 2021
Fix false positive stringop-truncation warning/error with GCC 10 on s390x by indicating GCC to explicitly ignore this case, as it is clearly a false positive (NUL is set in the following line).

This allow the compilation to succeed with -Werror on.

Fixes: swaywm#2018
emersion pushed a commit that referenced this issue Mar 8, 2021
Fix false positive stringop-truncation warning/error with GCC 10 on s390x by indicating GCC to explicitly ignore this case, as it is clearly a false positive (NUL is set in the following line).

This allow the compilation to succeed with -Werror on.

Fixes: #2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant