Skip to content

Commit ea3592d

Browse files
authored
bpo-36365: Fix compiler warning in structseq.c (GH-12451)
1 parent f7959a9 commit ea3592d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Objects/structseq.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,16 @@ 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);
188-
pbuf += len;
185+
assert(TYPE_MAXSIZE < sizeof(buf));
186+
len = strlen(typ->tp_name);
187+
if (len <= TYPE_MAXSIZE) {
188+
strcpy(pbuf, typ->tp_name);
189+
pbuf += len;
190+
}
191+
else {
192+
strncpy(pbuf, typ->tp_name, TYPE_MAXSIZE);
193+
pbuf += TYPE_MAXSIZE;
194+
}
189195
*pbuf++ = '(';
190196

191197
for (i=0; i < VISIBLE_SIZE(obj); i++) {

0 commit comments

Comments
 (0)