diff options
author | Benjamin Peterson <benjamin@python.org> | 2019-11-07 15:06:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-07 15:06:28 (GMT) |
commit | f32bcf8c27f3681407707bbb029323eb340d3c4b (patch) | |
tree | 1c6d804a1562ac4f5b5734c18c8635fd7822fb8f /Modules | |
parent | 089e5f52a34377193a9e6c03088114b14c8507af (diff) | |
download | cpython-f32bcf8c27f3681407707bbb029323eb340d3c4b.zip cpython-f32bcf8c27f3681407707bbb029323eb340d3c4b.tar.gz cpython-f32bcf8c27f3681407707bbb029323eb340d3c4b.tar.bz2 |
[2.7] bpo-38730: Fix -Wstringop-truncation warnings. (GH-17075)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/getpath.c | 2 | ||||
-rw-r--r-- | Modules/parsermodule.c | 11 | ||||
-rw-r--r-- | Modules/readline.c | 2 | ||||
-rw-r--r-- | Modules/signalmodule.c | 6 | ||||
-rw-r--r-- | Modules/zipimport.c | 6 |
5 files changed, 15 insertions, 12 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c index c42ce31..092ccc7 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -486,7 +486,7 @@ calculate_path(void) if (tmpbuffer[0] == SEP) /* tmpbuffer should never be longer than MAXPATHLEN, but extra check does not hurt */ - strncpy(argv0_path, tmpbuffer, MAXPATHLEN); + strncpy(argv0_path, tmpbuffer, MAXPATHLEN + 1); else { /* Interpret relative to progpath */ reduce(argv0_path); diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index fcc618d..759f0ff 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -1055,14 +1055,15 @@ validate_numnodes(node *n, int num, const char *const name) static int validate_terminal(node *terminal, int type, char *string) { - int res = (validate_ntype(terminal, type) - && ((string == 0) || (strcmp(string, STR(terminal)) == 0))); - - if (!res && !PyErr_Occurred()) { + if (!validate_ntype(terminal, type)) { + return 0; + } + if (string != NULL && strcmp(string, STR(terminal)) != 0) { PyErr_Format(parser_error, "Illegal terminal: expected \"%s\"", string); + return 0; } - return (res); + return 1; } diff --git a/Modules/readline.c b/Modules/readline.c index 0262135..64bb19a 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -1180,7 +1180,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) q = p; p = PyMem_Malloc(n+2); if (p != NULL) { - strncpy(p, q, n); + memcpy(p, q, n); p[n] = '\n'; p[n+1] = '\0'; } diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 8628f7a..88b4711 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -173,8 +173,10 @@ trip_signal(int sig_num) cleared in PyErr_CheckSignals() before .tripped. */ is_tripped = 1; Py_AddPendingCall(checksignals_witharg, NULL); - if (wakeup_fd != -1) - write(wakeup_fd, "\0", 1); + if (wakeup_fd != -1) { + int rc = write(wakeup_fd, "\0", 1); + (void)rc; + } } static void diff --git a/Modules/zipimport.c b/Modules/zipimport.c index 1691773..8ec2475 100644 --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -714,8 +714,8 @@ read_directory(const char *archive) unsigned int count, i; unsigned char buffer[46]; size_t length; - char path[MAXPATHLEN + 5]; - char name[MAXPATHLEN + 5]; + char name[MAXPATHLEN + 1]; + char path[2*MAXPATHLEN + 2]; /* archive + SEP + name + '\0' */ const char *errmsg = NULL; if (strlen(archive) > MAXPATHLEN) { @@ -838,7 +838,7 @@ read_directory(const char *archive) } } - strncpy(path + length + 1, name, MAXPATHLEN - length - 1); + memcpy(path + length + 1, name, name_size + 1); t = Py_BuildValue("sHIIkHHI", path, compress, data_size, file_size, file_offset, time, date, crc); |