[issue36365] Objects/structseq.c: warning: 'strncpy' specified bound depends on the length of the source argument

STINNER Victor report at bugs.python.org
Tue Mar 19 10:57:37 EDT 2019


New submission from STINNER Victor <vstinner at redhat.com>:

Warning seen on Fedora 29 with GCC 8.3.1 20190223 (Red Hat 8.3.1-2):

Objects/structseq.c: In function 'structseq_repr':
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 :
           ^~~~~~~~~~~~~~~~~~~~

Attached PR rewrites structseq_repr() using _PyUnicodeWriter for better performance and remove the arbitrary limit of 512 bytes.

----------
components: Interpreter Core
messages: 338361
nosy: vstinner
priority: normal
severity: normal
status: open
title: Objects/structseq.c: warning: 'strncpy' specified bound depends on the length of the source argument
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36365>
_______________________________________


More information about the Python-bugs-list mailing list