Skip to content

[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
mainfrom
repo-assist/fix-vsnprintf-float-sign-flags-2026-04-21-92081d498d237fff
Draft

[Repo Assist] fix: apply flag_plus and flag_space to floating-point in l_vsnprintf#143
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-vsnprintf-float-sign-flags-2026-04-21-92081d498d237fff

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist.

Summary

flag_plus (+) and flag_space ( ) were parsed in the l_vsnprintf format loop but never applied to %f/%e/%g output — 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.14 silently produced 3.14 instead of +3.14.

Fix

Introduce a single dsign variable capturing all three sign cases:

char dsign = dneg ? '-' : (flag_plus ? '+' : (flag_space ? ' ' : 0));

Use dsign consistently 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.

Generated by 🌈 Repo Assist at {run-started}. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1f672aef974f4246124860fc532f82fe8a93a57e

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants