Skip to content

Commit 9890520

Browse files
authored
Fix compiler warning in structseq_repr() (GH-10841)
Replace strncpy() with memcpy() in structseq_repr() to fix the following compiler warning: Objects/structseq.c:187:5: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=] strncpy(pbuf, typ->tp_name, len); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Objects/structseq.c:185:11: note: length computed here len = strlen(typ->tp_name) > TYPE_MAXSIZE ? TYPE_MAXSIZE : The function writes the terminating NUL byte later.
1 parent 503ce5c commit 9890520

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Objects/structseq.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ structseq_repr(PyStructSequence *obj)
182182
endofbuf= &buf[REPR_BUFFER_SIZE-5];
183183

184184
/* "typename(", limited to TYPE_MAXSIZE */
185-
len = strlen(typ->tp_name) > TYPE_MAXSIZE ? TYPE_MAXSIZE :
186-
strlen(typ->tp_name);
187-
strncpy(pbuf, typ->tp_name, len);
185+
len = strlen(typ->tp_name);
186+
len = Py_MIN(len, TYPE_MAXSIZE);
187+
memcpy(pbuf, typ->tp_name, len);
188188
pbuf += len;
189189
*pbuf++ = '(';
190190

0 commit comments

Comments
 (0)