Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
skirpichev opened this issue Dec 12, 2024 · 1 comment
Closed

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

skirpichev opened this issue Dec 12, 2024 · 1 comment
Labels
build The build process and cross-build interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@skirpichev
Copy link
Member

skirpichev commented Dec 12, 2024

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

@skirpichev skirpichev added the type-bug An unexpected behavior, bug, or error label Dec 12, 2024
@tomasr8
Copy link
Member

tomasr8 commented Dec 12, 2024

Using memcpy instead of strncpy gets rid of the warning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants