Skip to content

Commit 1600f60

Browse files
authored
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); ^~~~~~~~~
1 parent b7c2182 commit 1600f60

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Modules/readline.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ static char *
12401240
call_readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
12411241
{
12421242
size_t n;
1243-
char *p, *q;
1243+
char *p;
12441244
int signal;
12451245

12461246
#ifdef SAVE_LOCALE
@@ -1297,10 +1297,10 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
12971297
}
12981298
/* Copy the malloc'ed buffer into a PyMem_Malloc'ed one and
12991299
release the original. */
1300-
q = p;
1300+
char *q = p;
13011301
p = PyMem_RawMalloc(n+2);
13021302
if (p != NULL) {
1303-
strncpy(p, q, n);
1303+
memcpy(p, q, n);
13041304
p[n] = '\n';
13051305
p[n+1] = '\0';
13061306
}

0 commit comments

Comments
 (0)