classification
Title: Objects/structseq.c: warning: 'strncpy' specified bound depends on the length of the source argument
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: vstinner
Priority: normal Keywords: patch

Created on 2019-03-19 14:57 by vstinner, last changed 2019-03-19 23:32 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 12440 merged vstinner, 2019-03-19 14:58
PR 12451 merged vstinner, 2019-03-19 23:15
Messages (3)
msg338361 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-19 14:57
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.
msg338416 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-19 23:05
New changeset c70ab02df2894c34da2223fc3798c0404b41fd79 by Victor Stinner in branch 'master':
bpo-36365: Rewrite structseq_repr() using _PyUnicodeWriter (GH-12440)
https://github.com/python/cpython/commit/c70ab02df2894c34da2223fc3798c0404b41fd79
msg338419 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-19 23:32
New changeset ea3592d7ef6308bf9f6c7d86556f9b36f5ca0060 by Victor Stinner in branch '3.7':
bpo-36365: Fix compiler warning in structseq.c (GH-12451)
https://github.com/python/cpython/commit/ea3592d7ef6308bf9f6c7d86556f9b36f5ca0060
History
Date User Action Args
2019-03-19 23:32:21vstinnersetmessages: + msg338419
2019-03-19 23:15:24vstinnersetpull_requests: + pull_request12405
2019-03-19 23:06:20vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-03-19 23:05:55vstinnersetmessages: + msg338416
2019-03-19 14:58:53vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request12395
2019-03-19 14:57:37vstinnercreate