[Python-checkins] Fix compiler warning in call_readline() (GH-10820)

Victor Stinner webhook-mailer at python.org
Fri Nov 30 09:03:56 EST 2018


https://github.com/python/cpython/commit/1600f60414e620c4298c15dac803427d8f0a977c
commit: 1600f60414e620c4298c15dac803427d8f0a977c
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018年11月30日T15:03:53+01:00
summary:
Fix compiler warning in call_readline() (GH-10820)
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);
 ^~~~~~~~~
files:
M Modules/readline.c
diff --git a/Modules/readline.c b/Modules/readline.c
index 7756e6b2bc75..7f366aabfb4f 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -1240,7 +1240,7 @@ static char *
 call_readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
 {
 size_t n;
- char *p, *q;
+ char *p;
 int signal;
 
 #ifdef SAVE_LOCALE
@@ -1297,10 +1297,10 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
 }
 /* Copy the malloc'ed buffer into a PyMem_Malloc'ed one and
 release the original. */
- q = p;
+ char *q = p;
 p = PyMem_RawMalloc(n+2);
 if (p != NULL) {
- strncpy(p, q, n);
+ memcpy(p, q, n);
 p[n] = '\n';
 p[n+1] = '0円';
 }


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /