-
Notifications
You must be signed in to change notification settings - Fork 343
Fix #2777, compiler false positive in xcursor.c #2838
Conversation
This reverts commit 7dffe93, which introduced another linter error with -O3: error: ‘strncat’ specified bound 7 equals source length [-Werror=stringop-overflow=] This makes sense because strncat(dest, "cursors", strlen("cursors")) is moot in security point of view. The next commit will replace strncpy() with memcpy(), so let's restore the original implementation.
Since len <= strlen(elt) is known, we don't need a str*() function. Let's simply do memcpy() to suppress linter false positive. Fixes swaywm#2777.
@yuja can you reproduce the original warning to verify that this fixes it? I don't recall experiencing it myself, in which case I'm unable to verify it as fixed. |
Sorry, I can't reproduce the original truncation warning even with s390x-linux-gnu-gcc-10. Maybe need an s390x VM? The use of memcpy() is documented way to suppress the false positive, so I think it would https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstringop-truncation |
The manual says:
However we expect the result to be NUL-terminated here. |
No, we don't always expect that. Since |
The result is the output of the function, not the input. |
Yes. I mean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I see. So the memcpy
can never copy past the end of elt
.
Thanks for the explanation. This file is terrible.
This reverts commit 7dffe93, which introduced
another linter error with -O3:
and replace strncpy() with memcpy() to suppress the original warning.