Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Notice:These codes show bugs in Erlang's SUB BINARY OPTIMIZED mechanism
- -module(dame_shit).
- -export([main/0, dame_shit/1, dame_shit2/1]).
- dame_shit(Bin) ->
- dame_shit(Bin, not_found).
- dame_shit(Bin, found) ->
- {found, Bin};
- dame_shit(<<"\r\n", T/binary>>, not_found) ->
- dame_shit(T, found);
- dame_shit(<<B, T/binary>>, not_found) ->
- io:format("B=~c~n", [B]),
- dame_shit(T, not_found);
- dame_shit(<<>>, _) ->
- not_found.
- dame_shit2(Bin) ->
- dame_shit2(Bin, not_found).
- dame_shit2(Bin, _, found) ->
- {found, Bin};
- dame_shit2(<<"\r\n", T/binary>>=UnusedBinary, not_found) ->
- dame_shit2(T, found);
- dame_shit2(<<B, T/binary>>, not_found) ->
- io:format("B=~c~n", [B]),
- dame_shit2(T, not_found);
- dame_shit2(<<>>, _) ->
- not_found.
- main() ->
- io:format("Find '\\r\\n' result1: ~p~n", [dame_shit(<<"oops\r\nsomething maybe wrong!">>)]),
- io:format("Find '\\r\\n' result2: ~p~n", [dame_shit2(<<"oops\r\nsomething maybe wrong!">>)]),
- ok.
Add Comment
Please, Sign In to add comment