summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-03-20 01:00:41 +0100
committerGitHub <noreply@github.com>2019-03-20 01:00:41 +0100
commitef10f886ae21787ba88b04a2d4125727c9d15f59 (patch)
tree1e2882c59c3cb29db310fb3005d7790a2c432a6e /Modules
parentea3592d7ef6308bf9f6c7d86556f9b36f5ca0060 (diff)
downloadcpython-git-ef10f886ae21787ba88b04a2d4125727c9d15f59.tar.gz
Fix compiler warning in call_readline() (GH-10820) (GH-12452)
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 1600f60414e620c4298c15dac803427d8f0a977c)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/readline.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Modules/readline.c b/Modules/readline.c
index fa7e7d18e5..57335fe911 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -1239,7 +1239,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
@@ -1296,10 +1296,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';
}