File 0308-stdlib-Fix-bugs-in-eval_bits.patch of Package erlang
From faf0582e764d2eb902c243ca25173a0327efbaa6 Mon Sep 17 00:00:00 2001
From: Hans Bolinder <hasse@erlang.org>
Date: Mon, 9 Mar 2020 14:53:04 +0100
Subject: [PATCH] stdlib: Fix bugs in eval_bits
---
 lib/stdlib/src/eval_bits.erl       | 15 +++++++++++++--
 lib/stdlib/test/erl_eval_SUITE.erl | 22 ++++++++++++++++++++--
 2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/lib/stdlib/src/eval_bits.erl b/lib/stdlib/src/eval_bits.erl
index 15abb6166b..01b83fb918 100644
--- a/lib/stdlib/src/eval_bits.erl
+++ b/lib/stdlib/src/eval_bits.erl
@@ -81,8 +81,15 @@ eval_field({bin_element, Line, {string, _, S}, Size0, Options0}, Bs0, Fun) ->
         make_bit_type(Line, Size0, Options0),
     {value,Size,Bs1} = Fun(Size1, Bs0),
     Res = << <<(eval_exp_field1(C, Size, Unit,
-				Type, Endian, Sign))/binary>> ||
+				Type, Endian, Sign))/bitstring>> ||
 	      C <- S >>,
+    case S of
+        "" -> % find errors also when the string is empty
+            _ = eval_exp_field1(0, Size, Unit, Type, Endian, Sign),
+            ok;
+        _ ->
+            ok
+    end,
     {Res,Bs1};
 eval_field({bin_element,Line,E,Size0,Options0}, Bs0, Fun) ->
     {value,V,Bs1} = Fun(E, Bs0),
@@ -119,10 +126,14 @@ eval_exp_field(Val, _Size, _Unit, utf16, big, _) ->
     <<Val/big-utf16>>;
 eval_exp_field(Val, _Size, _Unit, utf16, little, _) ->
     <<Val/little-utf16>>;
+eval_exp_field(Val, _Size, _Unit, utf16, native, _) ->
+    <<Val/native-utf16>>;
 eval_exp_field(Val, _Size, _Unit, utf32, big, _) ->
     <<Val/big-utf32>>;
 eval_exp_field(Val, _Size, _Unit, utf32, little, _) ->
     <<Val/little-utf32>>;
+eval_exp_field(Val, _Size, _Unit, utf32, native, _) ->
+    <<Val/native-utf32>>;
 eval_exp_field(Val, Size, Unit, float, little, _) ->
     <<Val:(Size*Unit)/float-little>>;
 eval_exp_field(Val, Size, Unit, float, native, _) ->
diff --git a/lib/stdlib/test/erl_eval_SUITE.erl b/lib/stdlib/test/erl_eval_SUITE.erl
index 2e4a5f320f..77e56b0712 100644
--- a/lib/stdlib/test/erl_eval_SUITE.erl
+++ b/lib/stdlib/test/erl_eval_SUITE.erl
@@ -47,7 +47,8 @@
 	 zero_width/1,
          eep37/1,
          eep43/1,
-         otp_15035/1]).
+         otp_15035/1,
+         otp_16545/1]).
 
 %%
 %% Define to run outside of test server
@@ -86,7 +87,7 @@ all() ->
      otp_6539, otp_6543, otp_6787, otp_6977, otp_7550,
      otp_8133, otp_10622, otp_13228,
      funs, try_catch, eval_expr_5, zero_width,
-     eep37, eep43, otp_15035].
+     eep37, eep43, otp_15035, otp_16545].
 
 groups() -> 
     [].
@@ -1487,6 +1488,23 @@ otp_14708(Config) when is_list(Config) ->
           {e, d}),
     ok.
 
+otp_16545(Config) when is_list(Config) ->
+    check(fun() -> <<$W/utf16-native>> end,
+          "<<$W/utf16-native>>.",
+          <<0,$W>>),
+    check(fun() -> <<$W/utf32-native>> end,
+          "<<$W/utf32-native>>.",
+          <<$W,0,0,0>>),
+    check(fun() -> <<10/unsigned,"fgbz":86>> end,
+          "<<10/unsigned,\"fgbz\":86>>.",
+          <<10,0,0,0,0,0,0,0,0,0,1,152,0,0,0,0,0,0,0,0,0,6,112,0,0,
+            0,0,0,0,0,0,0,24,128,0,0,0,0,0,0,0,0,0,122>>),
+    check(fun() -> <<"":16/signed>> end,
+          "<<\"\":16/signed>>.",
+          <<>>),
+    error_check("<<\"\":problem/signed>>.", badarg),
+    ok.
+
 %% Check the string in different contexts: as is; in fun; from compiled code.
 check(F, String, Result) ->
     check1(F, String, Result),
-- 
2.16.4