Skip to content

Instantly share code, notes, and snippets.

@Arbow
Created July 28, 2008 02:10
Show Gist options
  • Save Arbow/2828 to your computer and use it in GitHub Desktop.
Save Arbow/2828 to your computer and use it in GitHub Desktop.
These codes show bugs in Erlang's SUB BINARY OPTIMIZED mechanism
%% 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment