Skip to content

#5629: fail with ExFailure on scanf format ending in dangling %#5638

Merged
yegor256 merged 1 commit into
objectionary:masterfrom
morphqdd:5629
Jul 19, 2026
Merged

#5629: fail with ExFailure on scanf format ending in dangling %#5638
yegor256 merged 1 commit into
objectionary:masterfrom
morphqdd:5629

Conversation

@morphqdd

Copy link
Copy Markdown
Contributor

Closes #5629.

EOscanf.lambda() builds the match regex in a first loop, where a trailing lone % sets literal = true and appends nothing, without raising any error for the dangling, never-completed specifier. The extraction loop then locates that % via frmt.indexOf('%') and reads the following char with frmt.charAt(idx + 1). When the % is the last character of the format, idx + 1 == frmt.length(), and a raw java.lang.StringIndexOutOfBoundsException escapes instead of a proper ExFailure.

This adds a check right after the first loop: if literal is still true once the loop ends, the format string has a dangling % with no specifier after it, so it now fails fast with a clear ExFailure, matching the existing pattern used for an unsupported specifier (the default: branch a few lines above).

Added EOscanfTest (a Java unit test asserting ExFailure is thrown for scanf "hello%" "hello") and a --> on-scanf-with-dangling-percent EO-level example in scanf.eo, next to the two existing on-scanf-with-* negative examples for this object.

Verified locally: the new tests pass, EOstringTest (51 tests) and the generated EOscanfEOAtomTest (15 tests, including the new example) pass, and qulice is clean.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Benchmark Comparison Unavailable

Unfortunately, one of the benchmarks is missing, and we couldn't generate a performance comparison report.

Please ensure that both the base and PR benchmark results are available for analysis.

@yegor256
yegor256 merged commit 1052d1e into objectionary:master Jul 19, 2026
26 checks passed
@0crat

0crat commented Jul 19, 2026

Copy link
Copy Markdown

@morphqdd Thanks for the contribution! You've earned +16 points. Please, keep them coming. Your running score is +1274; 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.

scanf crashes with StringIndexOutOfBoundsException on a format ending in a lone %

3 participants