Fix compiler warning in call_readline()#10820
Merged
vstinner merged 1 commit intopython:masterfrom Nov 30, 2018
vstinner:readline_strncpy
Merged
Fix compiler warning in call_readline()#10820vstinner merged 1 commit intopython:masterfrom vstinner:readline_strncpy
vstinner merged 1 commit intopython:masterfrom
vstinner:readline_strncpy
Conversation
Replace strncpy() with memcpy() in call_readline() to fix the
following warning, the NUL byte is written manually just after:
Modules/readline.c: In function ‘call_readline’:
Modules/readline.c:1303:9: warning: ‘strncpy’ output truncated before
terminating nul copying as many bytes from a string as its length
[-Wstringop-truncation]
strncpy(p, q, n);
^~~~~~~~~~~~~~~~
Modules/readline.c:1279:9: note: length computed here
n = strlen(p);
^~~~~~~~~
Member
Author
|
@serhiy-storchaka: Would you mind to double check this change? I don't want to introduce worse code when trying to fix a security issue/compiler warning :-) |
| { | ||
| size_t n; | ||
| char *p, *q; | ||
| char *p; |
Member
There was a problem hiding this comment.
Why the declaration of q has been moved?
Member
Author
There was a problem hiding this comment.
I like to move variable declaration closer to where they are used. That's now possible thanks to C99 (required by PEP 7 since Python 3.6). @methane and me are moving all variables one by one :-D But only when we already modify something else in the code.
IMHO the main benefit is to see more easily the scope of a variable. Sometimes, it helps to detect that a subfunction should be created.
Member
|
Using |
vstinner
added a commit
that referenced
this pull request
Mar 20, 2019
Replace strncpy() with memcpy() in call_readline() to fix the
following warning, the NUL byte is written manually just after:
Modules/readline.c: In function ‘call_readline’:
Modules/readline.c:1303:9: warning: ‘strncpy’ output truncated before
terminating nul copying as many bytes from a string as its length
[-Wstringop-truncation]
strncpy(p, q, n);
^~~~~~~~~~~~~~~~
Modules/readline.c:1279:9: note: length computed here
n = strlen(p);
^~~~~~~~~
(cherry picked from commit 1600f60)
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.
Replace strncpy() with memcpy() in call_readline() to fix the
following warning, the NUL byte is written manually just after:
Modules/readline.c: In function ‘call_readline’:
Modules/readline.c:1303:9: warning: ‘strncpy’ output truncated before
terminating nul copying as many bytes from a string as its length
[-Wstringop-truncation]
strncpy(p, q, n);
^~~~~~~~~~~~~~~~
Modules/readline.c:1279:9: note: length computed here
n = strlen(p);
^~~~~~~~~