Skip to content

stdlib: Fix unicode_util:gc/1 breaking binary continuations - #11464

Merged
dgud merged 1 commit into
erlang:maintfrom
dgud:dgud/string/bin_search/GH-11380/OTP-20296
Aug 19, 2026
Merged

stdlib: Fix unicode_util:gc/1 breaking binary continuations#11464
dgud merged 1 commit into
erlang:maintfrom
dgud:dgud/string/bin_search/GH-11380/OTP-20296

Conversation

@dgud

@dgud dgud commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

The gc/1 fast-path for $\r was calling cp(R0) and returning [CP|T] when \r was not followed by \n. This "exploded" the binary tail into mixed chardata (integers + binary fragments), which downstream functions in string.erl (bin_search_loop, bin_search_inv_n) could not handle — they expect
[BinR|Cont] when is_binary(BinR).

This caused string:trim/3 to return wrong results or crash with {case_clause,[]} when trimming strings containing binaries followed by another list element, and the binary contained $\r not followed by $\n.

Fix: return the original input (Str) instead of [CP|cp(R0)], consistent with what gc_1/1 already does.

Closes #11380

@dgud dgud self-assigned this Aug 11, 2026
@dgud dgud added team:PS Assigned to OTP team PS bug Issue is reported as a bug labels Aug 11, 2026
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

CT Test Results

    2 files    100 suites   1h 9m 17s ⏱️
2 301 tests 2 250 ✅ 51 💤 0 ❌
2 721 runs  2 665 ✅ 56 💤 0 ❌

Results for commit 04fa12b.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

garazdawi
garazdawi previously approved these changes Aug 11, 2026
Comment thread lib/stdlib/test/unicode_util_SUITE.erl Outdated
The gc/1 fast-path for $\r was calling cp(R0) and returning
[CP|T] when \r was not followed by \n. This "exploded" the
binary tail into mixed chardata (integers + binary fragments),
which downstream functions in string.erl (bin_search_loop,
bin_search_inv_n) could not handle — they expect
[BinR|Cont] when is_binary(BinR).

This caused string:trim/3 to return wrong results or crash
with {case_clause,[]} when trimming strings containing binaries
followed by another list element, and the binary contained $\r
not followed by $\n.

Fix: return the original input (Str) instead of [CP|cp(R0)],
consistent with what gc_1/1 already does.

Closes erlang#11380
@dgud
dgud force-pushed the dgud/string/bin_search/GH-11380/OTP-20296 branch from 9cfb9a0 to 04fa12b Compare August 11, 2026 13:05
@dgud dgud added the testing currently being tested, tag is used by OTP internal CI label Aug 17, 2026
@dgud
dgud merged commit 74313f9 into erlang:maint Aug 19, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue is reported as a bug team:PS Assigned to OTP team PS testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants