Guest User

Untitled

a guest
Feb 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. %% Notice:These codes show bugs in Erlang's SUB BINARY OPTIMIZED mechanism
  2. -module(dame_shit).
  3. -export([main/0, dame_shit/1, dame_shit2/1]).
  4.  
  5. dame_shit(Bin) ->
  6. dame_shit(Bin, not_found).
  7. dame_shit(Bin, found) ->
  8. {found, Bin};
  9. dame_shit(<<"\r\n", T/binary>>, not_found) ->
  10. dame_shit(T, found);
  11. dame_shit(<<B, T/binary>>, not_found) ->
  12. io:format("B=~c~n", [B]),
  13. dame_shit(T, not_found);
  14. dame_shit(<<>>, _) ->
  15. not_found.
  16.  
  17. dame_shit2(Bin) ->
  18. dame_shit2(Bin, not_found).
  19. dame_shit2(Bin, _, found) ->
  20. {found, Bin};
  21. dame_shit2(<<"\r\n", T/binary>>=UnusedBinary, not_found) ->
  22. dame_shit2(T, found);
  23. dame_shit2(<<B, T/binary>>, not_found) ->
  24. io:format("B=~c~n", [B]),
  25. dame_shit2(T, not_found);
  26. dame_shit2(<<>>, _) ->
  27. not_found.
  28.  
  29. main() ->
  30. io:format("Find '\\r\\n' result1: ~p~n", [dame_shit(<<"oops\r\nsomething maybe wrong!">>)]),
  31. io:format("Find '\\r\\n' result2: ~p~n", [dame_shit2(<<"oops\r\nsomething maybe wrong!">>)]),
  32. ok.
Add Comment
Please, Sign In to add comment