]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36365: Fix compiler warning in structseq.c (GH-12451)
authorVictor Stinner <vstinner@redhat.com>
Tue, 19 Mar 2019 23:32:11 +0000 (00:32 +0100)
committerGitHub <noreply@github.com>
Tue, 19 Mar 2019 23:32:11 +0000 (00:32 +0100)
Objects/structseq.c

index 900aaba7c150cb51cb63789b5156963c6a067f12..e48165dcd0087f5c34c99a8947260ea04246681e 100644 (file)
@@ -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++) {