Skip to content

WIP: Replace dangerous old string functions with less horrible variants, for -fbounds-safety compatibility - #24

Draft
seanm wants to merge 2 commits into
InsightSoftwareConsortium:masterfrom
seanm:kill-old-str-fns
Draft

WIP: Replace dangerous old string functions with less horrible variants, for -fbounds-safety compatibility#24
seanm wants to merge 2 commits into
InsightSoftwareConsortium:masterfrom
seanm:kill-old-str-fns

Conversation

@seanm

@seanm seanm commented Jan 14, 2026

Copy link
Copy Markdown
Collaborator

@hjmjohnson this one needs careful checking.

Also it's not done yet, I have to do some cmake stuff to compile the new file.

seanm added 2 commits January 14, 2026 16:50
The old functions can easily overflow buffers but also they are not allowed under -fbounds-safety at all.

Most cases were trivial.

strncpy() notably zeros the whole buffer, while strlcpy() does not. I examined each case carefully and in most cases calloc() was used previously meaning the buffer was already zeroed. In one case, added a memset(0) to preserve the behaviour, those I'm not sure it really is necessary.

In a few cases, too the opportunity to better move variable declaration to first usage or otherwise refactor a little bit.
strlcpy and strlcat came from OpenBSD and have since been added to other BSDs, macOS (and variants), and glibc (though only since 2.38). Add implementations for other platforms.
@seanm
seanm marked this pull request as draft July 31, 2026 19:54
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.

1 participant