Fix a false positive on gcc stringop-truncations warning#7268
Closed
ashfordium wants to merge 1 commit intoDynamoRIO:masterfrom
Closed
Fix a false positive on gcc stringop-truncations warning#7268ashfordium wants to merge 1 commit intoDynamoRIO:masterfrom
ashfordium wants to merge 1 commit intoDynamoRIO:masterfrom
Conversation
edeiana
requested changes
Feb 12, 2025
Contributor
edeiana
left a comment
There was a problem hiding this comment.
Please make a single PR (see #7267 (review))
| } | ||
| strncpy(buf, tmp_buf, len_var + 1); | ||
| buf[buflen - 1] = '\0'; | ||
| strncpy(buf, tmp_buf, buflen); |
Contributor
There was a problem hiding this comment.
We always prefer to null-terminate after strncpy(), it improves readability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #7267. Trying to fix these all up so I can build and test locally.
This one is a false positive on gcc's
stringop-truncationswarnings saying that thesizeargument tostrncpyis related to the source buffer and not the destination buffer.Based on the checks before this strncpy, it is safe to use
bufleninstead as the size and to remove the explicit null terminatorcheckset.The code assigns:
size_t len_var = strlen(tmp_buf);. At thestrncpy,len_var + 1 <= buflenso thenlen_var <= buflen - 1assuminglen_var + 1doesn't wrap, sostrncpycopies at mostbuflen-1characters, sostrncpy(...,..., buflen)guarantees a null terminator at or before the end ofbuf.