[erlang-bugs] binary_to_term--are these bugs?

Zvi <>
Sat Jan 19 21:16:48 CET 2008


Hi John,

can you please tell where these macros defines?

?FORALL
?WHENFAIL
?LET

TIA,
Zvi


John Hughes-7 wrote:
> 
> I've found some behaviour that I didn't expect in binary_to_term in R12B.
> I'm testing the QuickCheck property
> 
>  
> 
> prop_binary_to_term() ->
> 
>     ?FORALL(Bin,binary(),
> 
>               case catch binary_to_term(Bin) of
> 
>                    {'EXIT',{badarg,_}} ->
> 
>                        true;
> 
>                    Term ->
> 
>                        Bins = term_to_binaries(Term),
> 
>                        ?WHENFAIL(io:format("~p~n~p~n",[Term,Bins]),
> 
>                                    lists:any(fun(Bin2)->Bin=:=Bin2
> end,Bins))
> 
>               end).
> 
>  
> 
> term_to_binaries(T) ->
> 
>    
> lists:usort([term_to_binary(T,[{compressed,Level},{minor_version,Ver}])
> 
>                     || Level <- lists:seq(0,9),
> 
>                        Ver <- [0,1]]).
> 
>  
> 
> binary() ->
> 
>     ?LET(L,list(choose(0,255)),
> 
>            list_to_binary(L)).
> 
>  
> 
> The property says that any binary that binary_to_term successfully
> decodes,
> must be an encoding of that term using some compression level and minor
> version (the encoding options mentioned in the documentation). But it
> fails,
> on, for example:
> 
>  
> 
> <<131,97,0,0>>
> 
> 0
> 
> [<<131,97,0>>]
> 
>  
> 
> Or
> 
>  
> 
> <<131,106,0>>
> 
> []
> 
> [<<131,106>>]
> 
>  
> 
> Or
> 
>  
> 
> <<131,106,191,1,69,44,184,180,64>>
> 
> []
> 
> [<<131,106>>]
> 
>  
> 
> Or
> 
>  
> 
> <<131,67,0>>
> 
> '_'
> 
> [<<131,100,0,1,95>>]
> 
>  
> 
> where the output in each case is the binary, the term it decodes to, and
> the
> list of all possible encodings produced by term_to_binary.
> 
>  
> 
> Is this a bug?
> 
>  
> 
> John
> 
> 
> _______________________________________________
> erlang-bugs mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-bugs
> 

-- 
View this message in context: http://www.nabble.com/binary_to_term--are-these-bugs--tp14950900p14974713.html
Sent from the Erlang Bugs mailing list archive at Nabble.com.




More information about the erlang-bugs mailing list