--- /dev/null
+Fix problems identified by GCC's ``-Wstringop-truncation`` warning.
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);
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;
}
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';
}
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
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) {
}
}
- 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);
}
/* "typename(", limited to TYPE_MAXSIZE */
- len = strlen(typ->tp_name) > TYPE_MAXSIZE ? TYPE_MAXSIZE :
- strlen(typ->tp_name);
- strncpy(pbuf, typ->tp_name, len);
- pbuf += len;
+ pbuf = stpncpy(pbuf, typ->tp_name, TYPE_MAXSIZE);
*pbuf++ = '(';
for (i=0; i < VISIBLE_SIZE(obj); i++) {
}
plen = strlen(p);
- if (plen + nlen >= PY_SSIZE_T_MAX - 1) {
+ if (nlen >= PY_SSIZE_T_MAX - 1 - plen) {
PyErr_SetString(PyExc_OverflowError,
"private identifier too large to be mangled");
return NULL;
/* ident = "_" + p[:plen] + name # i.e. 1+plen+nlen bytes */
buffer = PyString_AS_STRING(ident);
buffer[0] = '_';
- strncpy(buffer+1, p, plen);
+ memcpy(buffer+1, p, plen);
strcpy(buffer+1+plen, name);
return ident;
}