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

Fix #2018, false positive -Wstringop-truncation warning #2768

Merged
merged 2 commits into from
Mar 8, 2021

Conversation

slyon
Copy link
Contributor

@slyon slyon commented 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: #2018

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
Copy link
Member

emersion commented Mar 3, 2021

I don't want to clutter the codebase with compiler-specific directives to disable warnings.

@slyon
Copy link
Contributor Author

slyon commented Mar 3, 2021

Many distributions build with treating warnings as errors, which makes the build fail in this case.
Do you see a better way to improve those two lines of code, to avoid that warning?

@kennylevinsen
Copy link
Member

Please see: https://github.com/swaywm/wlroots/wiki/Packaging-recommendations

For upstream, if the code is convoluted, improvement that happens to silence warnings is fine, but we shouldn't bend ourselves out of shape to silence a false positive. It should probably just be disabled in the meson file instead in that case.

@emersion
Copy link
Member

emersion commented Mar 3, 2021

Maybe try to pass len - 1, and check if len > 0?

@ascent12
Copy link
Member

ascent12 commented Mar 4, 2021

Many distributions build with treating warnings as errors

Not really related to the issue, but this is a terrible idea for distributors in general. -Werror is a developer thing.
Upgrading your compiler could lead to a massive portion of builds breaking, especially for false-positive heavy warnings like this one.

Instead of carrying workarounds upstream, it's a far better idea to just try and fix whatever is actually causing the warning.

strncat appends '\0' automatically and avoids the stringop-truncation
warning/error
@slyon
Copy link
Contributor Author

slyon commented Mar 4, 2021

I agree it is better to fix the actual problem, than cluttering the codebase with compiler specific directives.

What about just using strncat instead of strncpy? This will append the trailing \0 automatically, thus no warning.

Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@emersion emersion merged commit 7dffe93 into swaywm:master Mar 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

xcursor: strncpy truncation warning with GCC 10 on s390x
4 participants