Skip to content

Fix stringop-truncation warning - #1473

Merged
flyingmutant merged 1 commit into
cmus:masterfrom
chggr:fix-stringop-truncation-warning
Dec 12, 2025
Merged

flyingmutant merged 1 commit into
cmus:masterfrom
chggr:fix-stringop-truncation-warning

Conversation

@chggr

@chggr chggr commented Dec 7, 2025

Copy link
Copy Markdown
Contributor

When compiling with gcc 15.2.1 I get the following warning: pl_env.c:198:17: warning: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation].

Having a look at the code, it seems that strncpy is used to copy a string where the specified length equals the source string length, resulting in no null terminator being written. The code is explicitly handing the string construction in this case, adding delimiters and a final null terminator later. So the null-padding behaviour of strncpy is not really needed and we should directly use memcpy instead to fix the truncation warning.

@chggr
chggr force-pushed the fix-stringop-truncation-warning branch from 281ce6a to 9d2d58a Compare December 11, 2025 22:16
@flyingmutant
flyingmutant merged commit 56446f7 into cmus:master Dec 12, 2025
@chggr
chggr deleted the fix-stringop-truncation-warning branch December 12, 2025 20:57
@BrewTestBot BrewTestBot mentioned this pull request Oct 28, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants