GNU nano - Bugs: bug #57360, GCC -Wstringop-truncation warnings
You are not allowed to post comments on this tracker with your current authentication level.
bug #57360: GCC -Wstringop-truncation warnings
Submitter: | Brand Huntsman <brand> | ||
Submitted: | Thu 05 Dec 2019 04:57:17 AM UTC | ||
Severity: | 2 - Minor | Status: | Fixed |
Assigned to: | bens | Open/Closed: | Closed |
Jump to the original submission
Sun 08 Dec 2019 10:28:30 AM UTC, comment #8: |
Benno Schulenberg <bens> |
Fri 06 Dec 2019 08:49:21 PM UTC, comment #7: That patch fixed all the warnings. |
Brand Huntsman <brand> |
Fri 06 Dec 2019 11:38:20 AM UTC, comment #6: Does copying the full 32 bytes of the myhostname array avoid the warning? That is, does the attached patch avoid all three warnings? |
Benno Schulenberg <bens> |
Thu 05 Dec 2019 07:45:32 PM UTC, comment #5: The strncpy for mypwuid->pw_name doesn't warn because it has no statically known size. And always setting myhostname[31] to \0 doesn't help. |
Brand Huntsman <brand> |
Thu 05 Dec 2019 12:35:48 PM UTC, comment #4: As a test, I've replaced the relevant strncpy() with a memcpy(), and have seeded char myhostname[32] with "tralalalalalalalalalalalalalala". Then I've run nano with --locking and then opened the same file in another terminal with vim. Vim correctly shows the hostname of my laptop, without any trailing junk. So I think it's safe to use memcpy() here. |
Benno Schulenberg <bens> |
Thu 05 Dec 2019 11:40:27 AM UTC, comment #3: Copying any garbage after the \0 byte would probably not be a problem. But... maybe we should always set myhostname[31] = '\0', not only when errno == ENAMETOOLONG; maybe that gets rid of the warning? Because, why does the compiler not complain for the two neigbouring strncpy() statements? |
Benno Schulenberg <bens> |
Thu 05 Dec 2019 11:12:30 AM UTC, comment #2: -Wno-stringop-truncation works but that would suppress actual problems as well.
|
Brand Huntsman <brand> |
Thu 05 Dec 2019 10:44:27 AM UTC, comment #1: (My compiler does not yet know -Wstringop-truncation, so I cannot reproduce. It only knows -Wstringop-overflow, but even setting this to 4 does not produce any warnings.)
|
Benno Schulenberg <bens> |
Thu 05 Dec 2019 04:57:17 AM UTC, original submission:
GCC 9.2 or Gentoo's version now has -Wstringop-truncation enabled which throws three warnings when compiling nano. I don't see anything wrong with the code. The warnings have been cleaned up for readability.
|
Brand Huntsman <brand> |
Depends on the following items: None found
Items that depend on this one: None found
There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.
Follow 6 latest changes.
Date | Changed by | Updated Field | Previous Value | => | Replaced by |
---|---|---|---|---|---|
2019-12-24 | bens | Open/Closed | Open | Closed | |
2019-12-08 | bens | Status | In Progress | Fixed | |
2019-12-06 | bens | Attached File | - | Added 0001-build-avoid-three-compiler-warnings.patch, #48017 | |
Status | None | In Progress | |||
Assigned to | None | bens | |||
2019-12-05 | bens | Severity | 3 - Normal | 2 - Minor |
Powered by Savane 3.13-02a9.
Corresponding source code
Thanks for confirming. Pushed to master, commit 76d90617.