Skip to content

fix(#1366): decode formatter specifiers instead of matching raw hex in sprintf-constant-args - #1427

Merged
yegor256 merged 1 commit into
masterfrom
1366
Sep 9, 2026
Merged

yegor256 merged 1 commit into
masterfrom
1366

Conversation

@yegor256

@yegor256 yegor256 commented Sep 8, 2026

Copy link
Copy Markdown
Member

Problem

Closes #1366.

sprintf-constant-args selects the .printf dispatch correctly, but its formatter count is computed by searching the hex dump of the format string for the literal hex byte sequence of a bare specifier (2573 for %s, 2564 for %d, 2566 for %f, 2578 for %x, 2562 for %b). A specifier that carries a flag, width, or precision — e.g. %08.2f — inserts extra bytes between % and the conversion letter, so its hex sequence never matches and the lint silently misses the defect (0 formatters counted instead of 1).

Fix

Decode the hex-encoded bytes back into the actual characters (the same eo:hex-to-placeholder approach already used by the sibling lint sprintf-without-formatters.xsl), then count specifiers with a regex that understands %[N$][flags][width][.precision]conversion, consistent with how sprintf-without-formatters already detects formatters.

Testing

Added a pack, catches-printf-with-flagged-format-and-constant-args.yaml, using a real "%08.2f".printf (* "3.14") call with a constant string argument. It fails on master (0 defects reported instead of 1) and passes with this change. Ran the full LtByXslTest suite (517 tests) — all green, including the pre-existing sprintf-constant-args and sprintf-without-formatters packs.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TFrxLNmS5phrWQhwndWUCU


Generated by Claude Code

sprintf-constant-args counted a format specifier by looking for its
literal hex byte sequence (e.g. "2566" for "%f") inside the untouched
hex dump of the format string. A specifier carrying a flag, width or
precision (e.g. "%08.2f") inserts extra bytes between "%" and the
conversion letter, so its hex sequence never matched and the lint
silently missed the defect.

Decode the hex bytes back into the actual characters first (the same
approach sprintf-without-formatters already uses), then count
specifiers with a regex that understands flags, width and precision.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TFrxLNmS5phrWQhwndWUCU
@yegor256
yegor256 marked this pull request as ready for review September 8, 2026 06:48
Copilot AI lite review requested due to automatic review settings September 8, 2026 06:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@yegor256
yegor256 merged commit efb009a into master Sep 9, 2026
27 checks passed
@yegor256
yegor256 deleted the 1366 branch September 9, 2026 03:48

yegor256 commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

Merged, thanks! Reusing the eo:hex-to-placeholder approach from the sibling lint keeps the two consistent.


Generated by Claude Code

@0crat

0crat commented Sep 16, 2026

Copy link
Copy Markdown

@yegor256 Thanks for the contribution! You've earned +8 points for this: +16 as a basis; -8 for the lack of code review. Please, keep them coming. Your running score is +2338; don't forget to check your Zerocracy account too).

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.

sprintf-constant-args selects the removed Φ.txt.sprintf, so the rule never fires on current EO

4 participants