From 178536b0f238b36949a1724856375dcdbd2ffd61 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 20 Mar 2019 00:12:25 +0100 Subject: [PATCH] bpo-36365: Fix compiler warning in structseq.c --- Objects/structseq.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Objects/structseq.c b/Objects/structseq.c index 900aaba7c150cb5..e48165dcd0087f5 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -182,10 +182,16 @@ structseq_repr(PyStructSequence *obj) endofbuf= &buf[REPR_BUFFER_SIZE-5]; /* "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; + assert(TYPE_MAXSIZE < sizeof(buf)); + len = strlen(typ->tp_name); + if (len <= TYPE_MAXSIZE) { + strcpy(pbuf, typ->tp_name); + pbuf += len; + } + else { + strncpy(pbuf, typ->tp_name, TYPE_MAXSIZE); + pbuf += TYPE_MAXSIZE; + } *pbuf++ = '('; for (i=0; i < VISIBLE_SIZE(obj); i++) {