Skip to content

New warning in the main: Python/import.c [-Wstringop-truncation] #127864

@skirpichev

Description

@skirpichev

Bug report

Bug description:

$ cc --version|head -1
cc (Debian 12.2.0-14) 12.2.0
$ ./configure -q && make -s
In function ‘hashtable_key_from_2_strings’,
    inlined from ‘_extensions_cache_find_unlocked’ at Python/import.c:1266:17:
Python/import.c:1179:5: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
 1179 |     strncpy(key, str1_data, str1_len);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Python/import.c:1165:27: note: length computed here
 1165 |     Py_ssize_t str1_len = strlen(str1_data);
      |                           ^~~~~~~~~~~~~~~~~
Written build/lib.linux-x86_64-3.14/_sysconfigdata__linux_x86_64-linux-gnu.py
Written build/lib.linux-x86_64-3.14/_sysconfig_vars__linux_x86_64-linux-gnu.json
Checked 112 modules (34 built-in, 77 shared, 1 n/a on linux-x86_64, 0 disabled, 0 missing, 0 failed on import)

Edit: happens on non-debug builds.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildThe build process and cross-buildinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions