Skip to content

Fix -Werror=stringop-truncation build failure in fileutils.c#3350

Merged
iceman1001 merged 1 commit into
RfidResearchGroup:masterfrom
AlxCzl:fix-strcat
Jun 2, 2026
Merged

Fix -Werror=stringop-truncation build failure in fileutils.c#3350
iceman1001 merged 1 commit into
RfidResearchGroup:masterfrom
AlxCzl:fix-strcat

Conversation

@AlxCzl
Copy link
Copy Markdown
Contributor

@AlxCzl AlxCzl commented Jun 2, 2026

strncat(tmp_fullpath, path, sizeof(tmp_fullpath) - 1) into a zero-initialized buffer triggers -Wstringop-truncation on newer GCC because the copy length equals the buffer size, so GCC flags it as potentially truncating.

Replaced the strncat chain with a single snprintf call, which also fixes a secondary bug on the old line 3041 where the third argument to strncat was strlen(tmp_fullpath) - 1 (which is the current string length, not the remaining buffer space). In practice this means the append could overrun the buffer if path was short and d_name was long enough.

Before:

char tmp_fullpath[1023] = {0};
strncat(tmp_fullpath, path, sizeof(tmp_fullpath) - 1);
tmp_fullpath[1023] = 0x00;
strncat(tmp_fullpath, namelist[i]->d_name, strlen(tmp_fullpath) - 1);

After:

snprintf(tmp_fullpath, sizeof(tmp_fullpath), "%s%s", path, namelist[i]->d_name);

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

You are welcome to add an entry to the CHANGELOG.md as well

@iceman1001 iceman1001 merged commit e1228ee into RfidResearchGroup:master Jun 2, 2026
34 checks passed
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.

2 participants