diff options
author | John Högberg <john@erlang.org> | 2023-02-22 12:12:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-22 12:12:23 +0100 |
commit | 4e668b984ef53a6942d857aea82ebccce375e61a (patch) | |
tree | 2352c9e02d883c5188fc5b9594a527731a42a6d0 /lib/stdlib | |
parent | cfc86388f0536bb660728f1bc4784b90251e9a11 (diff) | |
parent | 3139ec6cb704e91035ee04a2da8ea11104c65ec1 (diff) | |
download | erlang-4e668b984ef53a6942d857aea82ebccce375e61a.tar.gz |
Merge pull request #6881 from sile/fix-escript-binary-stdin-bug
Fix a bug that `file:read(standard_io, ..)` unexpectedly returns `eof`
OTP-18486
PR-6881
Diffstat (limited to 'lib/stdlib')
-rw-r--r-- | lib/stdlib/src/io_lib.erl | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/lib/stdlib/src/io_lib.erl b/lib/stdlib/src/io_lib.erl index 9ef70008d6..7f8292e46f 100644 --- a/lib/stdlib/src/io_lib.erl +++ b/lib/stdlib/src/io_lib.erl @@ -808,23 +808,19 @@ collect_chars(Tag, Data, N) -> %% Now we are aware of encoding... collect_chars(start, Data, unicode, N) when is_binary(Data), is_integer(N) -> {Size,Npos} = count_and_find_utf8(Data,N), - if Size > N -> + if Size >= N -> {B1,B2} = split_binary(Data, Npos), {stop,B1,B2}; Size < N -> - {binary,[Data],N-Size}; - true -> - {stop,Data,eof} + {binary,[Data],N-Size} end; collect_chars(start, Data, latin1, N) when is_binary(Data), is_integer(N) -> Size = byte_size(Data), - if Size > N -> + if Size >= N -> {B1,B2} = split_binary(Data, N), {stop,B1,B2}; Size < N -> - {binary,[Data],N-Size}; - true -> - {stop,Data,eof} + {binary,[Data],N-Size} end; collect_chars(start,Data,_,N) when is_list(Data), is_integer(N) -> collect_chars_list([], N, Data); @@ -834,23 +830,19 @@ collect_chars({binary,Stack,_N}, eof, _,_) -> {stop,binrev(Stack),eof}; collect_chars({binary,Stack,N}, Data,unicode, _) when is_integer(N) -> {Size,Npos} = count_and_find_utf8(Data,N), - if Size > N -> + if Size >= N -> {B1,B2} = split_binary(Data, Npos), {stop,binrev(Stack, [B1]),B2}; Size < N -> - {binary,[Data|Stack],N-Size}; - true -> - {stop,binrev(Stack, [Data]),eof} + {binary,[Data|Stack],N-Size} end; collect_chars({binary,Stack,N}, Data,latin1, _) when is_integer(N) -> Size = byte_size(Data), - if Size > N -> + if Size >= N -> {B1,B2} = split_binary(Data, N), {stop,binrev(Stack, [B1]),B2}; Size < N -> - {binary,[Data|Stack],N-Size}; - true -> - {stop,binrev(Stack, [Data]),eof} + {binary,[Data|Stack],N-Size} end; collect_chars({list,Stack,N}, Data, _,_) when is_integer(N) -> collect_chars_list(Stack, N, Data); |