Skip to content

Fix: Replace unavailable snprintf with Rust formatting on Windows#133

Open
bardo84 wants to merge 2 commits intorunmat-org:mainfrom
bardo84:fix/windows-snprintf-compat
Open

Fix: Replace unavailable snprintf with Rust formatting on Windows#133
bardo84 wants to merge 2 commits intorunmat-org:mainfrom
bardo84:fix/windows-snprintf-compat

Conversation

@bardo84
Copy link
Copy Markdown
Contributor

@bardo84 bardo84 commented Jan 11, 2026

Problem


Note

Replaces C _snprintf/snprintf on Windows with a Rust platform_snprintf that parses and formats %e/%E/%f/%F/%g/%G with flags, width, and precision, including #, sign, zero-padding, alignment, and proper handling of NaN/Inf.

  • Unifies Windows path under #[cfg(windows)] and keeps libc snprintf for non-Windows
  • Adds c_int import and adjusts return sizing to match C semantics
  • Adds Windows-only tests verifying # flag behavior for special values and decimal insertion before exponent

Written by Cursor Bugbot for commit 64c2344. This will update automatically on new commits. Configure here.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 11, 2026

Someone is attempting to deploy a commit to the Dystr Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread crates/runmat-runtime/src/builtins/io/tabular/dlmwrite.rs
Comment thread crates/runmat-runtime/src/builtins/io/tabular/dlmwrite.rs Outdated
Comment thread crates/runmat-runtime/src/builtins/io/tabular/dlmwrite.rs Outdated
Comment thread crates/runmat-runtime/src/builtins/io/tabular/dlmwrite.rs Outdated
@nallana
Copy link
Copy Markdown
Contributor

nallana commented Jan 12, 2026

@bardo84 -- thanks for submitting this! I've cleared the CI/CD runners to run so the test suite can be evaluated on all platforms for the changeset. Can you please resolve the callouts provided by cursor BugBot? They generally seem like good catches.

@bardo84 bardo84 force-pushed the fix/windows-snprintf-compat branch from a66c4a7 to e0ff33a Compare January 13, 2026 23:28
Comment thread crates/runmat-runtime/src/builtins/io/tabular/dlmwrite.rs
fn format_with_spec(value: f64, spec: char, precision: Option<usize>) -> String {
match spec {
'e' => format!("{:.*e}", precision.unwrap_or(6), value),
'E' => format!("{:.*E}", precision.unwrap_or(6), value),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scientific notation exponent format differs from C standard

Low Severity

Rust's scientific notation format differs from C's %e/%E output. Rust produces exponents like "1.23e4" (no sign for positive, minimal digits), while C produces "1.23e+04" (explicit + sign, at least two digits). This affects all %e, %E, %g, and %G format specifiers and could cause compatibility issues with downstream tools or MATLAB workflows that expect C-style exponent formatting. The exponent_part is used directly from Rust's format output without normalization to C conventions.

Additional Locations (1)

Fix in Cursor Fix in Web

…g bugs

- Parse and preserve all printf format flags (+, -, space, 0, #) and width specifiers
- Fix Bug 1: # flag no longer appends decimal point to special float values (inf, nan)
- Fix Bug 2: # flag correctly inserts decimal point before exponent in exponential notation
- Add comprehensive tests for hash flag behavior with special values and exponents
- Restore full C-style printf format compatibility for Windows snprintf fallback
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

formatted.push('.');
}
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hash flag for %g format doesn't preserve trailing zeros

Medium Severity

The # flag for %g/%G format specifiers only adds a decimal point but doesn't preserve trailing zeros. In C's printf, %#g requires trailing zeros to NOT be removed from the fractional part. The current implementation unconditionally calls trim_trailing_decimal in format_general before the hash flag is checked in format_with_spec, so format strings like %#.5g with value 1.0 produce "1." instead of the expected "1.0000".

Additional Locations (1)

Fix in Cursor Fix in Web

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