[Repo Assist] fix: apply flag_plus and flag_space to floating-point in l_vsnprintf#143
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
flag_plus (+) and flag_space ( ) were parsed in the format loop but never applied to %f/%e/%g output — only integer formats used them. Root cause: the floating-point branch computed sign width using (dneg ? 1 : 0) and only emitted '-'; the dsign variable was never introduced for positive-sign flags. Fix: compute a single dsign character that captures all three sign cases (negative '-', flag_plus '+', flag_space ' '), then use it consistently in NaN, Inf, and normal-float width calculations and sign emission. Tests: add 9 new assertions covering %+f, % f, %+e, %+g for positive and negative values, and %+f / % f for infinity. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
38 tasks
26 tasks
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.
🤖 This is an automated pull request from Repo Assist.
Summary
flag_plus(+) andflag_space() were parsed in thel_vsnprintfformat loop but never applied to%f/%e/%goutput — only integer formats (%d,%i) used them.Root Cause
The floating-point branch computed sign width using
(dneg ? 1 : 0)and only emitted'-'for negative values. No sign character was computed for positive-sign flags, so%+f 3.14silently produced3.14instead of+3.14.Fix
Introduce a single
dsignvariable capturing all three sign cases:Use
dsignconsistently for NaN, Inf, and normal-float width calculation and sign emission.Test Status
Nine new assertions in
test_snprintf_float():%+f 3.14→+3.140000✅% f 3.14→3.140000✅%+e 1.0→+1.000000e+00✅%+g 100.0→+100✅%+f +inf→+inf✅% f +inf→inf✅Full Linux gcc+clang test suite: all PASS.