fix(devel): close va_list on every path in homa_snprintf - #101
Open
randomizedcoder wants to merge 1 commit into
Open
randomizedcoder wants to merge 1 commit into
randomizedcoder wants to merge 1 commit into
Conversation
homa_snprintf() called va_start(ap, format) at the top of the function but never called va_end(ap) on any of its return paths. The C standard requires each va_start to be paired with a va_end before the function returns; skipping it is undefined behavior and leaks the va_list on ABIs where va_start allocates (it is a no-op on the x86-64 SysV ABI, which is why no runtime failure is observed on this platform). Move va_start to just before the sole vsnprintf() call and va_end immediately after, so the va_list is opened and closed in one place and no early return can escape it. Gate: cppcheck --enable=all flags this as va_end_missing at homa_devel.c:490 before the fix and reports it clean after. The existing homa_snprintf unit regression stays green (test/unit homa_utils: 12/12). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug:
va_listopened but never closed inhoma_snprintf()va_start(ap, format)is executed at the top of the function, but none of the four return paths callva_end(ap). The C standard requires everyva_startto be paired with a matchingva_endbefore the function returns; omitting it is undefined behavior and leaks theva_liston ABIs whereva_startallocates. It happens to be a no-op on the x86-64 SysV ABI, which is why nothing fails at runtime on this platform — but it is still a portability/correctness defect.Fix
Open the
va_listimmediately before its only use and close it right after, so no early return can escape it:Verification (static gate + regression)
cppcheck --enable=all homa_devel.c. There is no runtime gate for this one: a missingva_endis a no-op on the x86-64 SysV ABI, so no unit test can observe it failing on this host — the authoritative red→green signal is the cppcheckva_end_missingfinding flipping from present to absent. The existinghoma_snprintfbehavior is unchanged; thehoma_utilsregression stays green (12/12).