Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
0228-stdlib-Correct-evaluation-of-bitstring-com...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0228-stdlib-Correct-evaluation-of-bitstring-comprehension.patch of Package erlang
From 5a356a6bf3f65f9b1bbdcafe7068647f240eef49 Mon Sep 17 00:00:00 2001 From: Hans Bolinder <hasse@erlang.org> Date: Wed, 7 Oct 2020 13:16:55 +0200 Subject: [PATCH 1/2] stdlib: Correct evaluation of bitstring comprehension If the Size expression cannot be evaluated, the binary pattern does not match. --- lib/stdlib/src/eval_bits.erl | 23 +++++++++++++++-------- lib/stdlib/test/erl_eval_SUITE.erl | 11 +++++++++-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/stdlib/src/eval_bits.erl b/lib/stdlib/src/eval_bits.erl index 5c75320de0..157d823a09 100644 --- a/lib/stdlib/src/eval_bits.erl +++ b/lib/stdlib/src/eval_bits.erl @@ -198,20 +198,27 @@ bin_gen_field({bin_element,Line,{string,SLine,S},Size0,Options0}, Bin0, Bs0, BBs0, Mfun, Efun) -> {Size1, [Type,{unit,Unit},Sign,Endian]} = make_bit_type(Line, Size0, Options0), - {value, Size, _BBs} = Efun(Size1, BBs0), - F = fun(C, Bin, Bs, BBs) -> - bin_gen_field1(Bin, Type, Size, Unit, Sign, Endian, - {integer,SLine,C}, Bs, BBs, Mfun) - end, - bin_gen_field_string(S, Bin0, Bs0, BBs0, F); + case catch Efun(Size1, BBs0) of + {value, Size, _BBs} -> % + F = fun(C, Bin, Bs, BBs) -> + bin_gen_field1(Bin, Type, Size, Unit, Sign, Endian, + {integer,SLine,C}, Bs, BBs, Mfun) + end, + bin_gen_field_string(S, Bin0, Bs0, BBs0, F) + end; bin_gen_field({bin_element,Line,VE,Size0,Options0}, Bin, Bs0, BBs0, Mfun, Efun) -> {Size1, [Type,{unit,Unit},Sign,Endian]} = make_bit_type(Line, Size0, Options0), V = erl_eval:partial_eval(VE), NewV = coerce_to_float(V, Type), - {value, Size, _BBs} = Efun(Size1, BBs0), - bin_gen_field1(Bin, Type, Size, Unit, Sign, Endian, NewV, Bs0, BBs0, Mfun). + case catch Efun(Size1, BBs0) of + {value, Size, _BBs} -> + bin_gen_field1(Bin, Type, Size, Unit, Sign, Endian, + NewV, Bs0, BBs0, Mfun); + _ -> + done + end. bin_gen_field_string([], Rest, Bs, BBs, _F) -> {match,Bs,BBs,Rest}; diff --git a/lib/stdlib/test/erl_eval_SUITE.erl b/lib/stdlib/test/erl_eval_SUITE.erl index a29b60cd1d..392e52bdb1 100644 --- a/lib/stdlib/test/erl_eval_SUITE.erl +++ b/lib/stdlib/test/erl_eval_SUITE.erl @@ -51,7 +51,8 @@ otp_15035/1, otp_16439/1, otp_14708/1, - otp_16545/1]). + otp_16545/1, + otp_16865/1]). %% %% Define to run outside of test server @@ -91,7 +92,7 @@ all() -> otp_6539, otp_6543, otp_6787, otp_6977, otp_7550, otp_8133, otp_10622, otp_13228, otp_14826, funs, try_catch, eval_expr_5, zero_width, - eep37, eep43, otp_15035, otp_16439, otp_14708, otp_16545]. + eep37, eep43, otp_15035, otp_16439, otp_14708, otp_16545, otp_16865]. groups() -> []. @@ -1745,6 +1746,12 @@ otp_16545(Config) when is_list(Config) -> error_check("<<\"\":problem/signed>>.", badarg), ok. +otp_16865(Config) when is_list(Config) -> + check(fun() -> << <<>> || <<34:(1/0)>> <= <<"string">> >> end, + "<< <<>> || <<34:(1/0)>> <= <<\"string\">> >>.", + <<>>), + ok. + %% Check the string in different contexts: as is; in fun; from compiled code. check(F, String, Result) -> check1(F, String, Result), -- 2.26.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor