Skip to content

Commit a930c81

Browse files
committed
Merge 'sverker/26/ets_fix_update_badarg/OTP-19962'
into 'sverker/27/ets_fix_update_badarg/OTP-19962'
2 parents c388a2d + dda8051 commit a930c81

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

erts/emulator/beam/erl_db.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,8 @@ BIF_RETTYPE ets_update_counter_4(BIF_ALIST_4)
16411641

16421642
DB_BIF_GET_TABLE(tb, DB_WRITE, LCK_WRITE_REC, BIF_ets_update_counter_4);
16431643

1644-
if (is_not_tuple(BIF_ARG_4)) {
1644+
if (is_not_tuple(BIF_ARG_4)
1645+
|| arityval(*tuple_val(BIF_ARG_4)) < tb->common.keypos) {
16451646
db_unlock(tb, LCK_WRITE_REC);
16461647
BIF_ERROR(BIF_P, BADARG);
16471648
}

lib/stdlib/test/ets_SUITE.erl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
fixtable_insert/1, rename/1, rename_unnamed/1, evil_rename/1,
6767
update_element/1, update_element_default/1, update_counter/1, evil_update_counter/1, partly_bound/1, match_heavy/1]).
6868
-export([update_counter_with_default/1]).
69-
-export([update_counter_with_default_bad_pos/1]).
69+
-export([update_counter_with_default_bad_pos/1,
70+
update_counter_with_default_bad_default/1]).
7071
-export([update_counter_table_growth/1]).
7172
-export([member/1]).
7273
-export([memory/1]).
@@ -156,6 +157,7 @@ all() ->
156157
update_counter, evil_update_counter,
157158
update_counter_with_default,
158159
update_counter_with_default_bad_pos,
160+
update_counter_with_default_bad_default,
159161
partly_bound,
160162
update_counter_table_growth,
161163
match_heavy, {group, fold}, member, t_delete_object,
@@ -3070,6 +3072,20 @@ update_counter_with_default_bad_pos_do(Opts) ->
30703072
0 = ets:info(T, size),
30713073
ok.
30723074

3075+
update_counter_with_default_bad_default(Config) when is_list(Config) ->
3076+
repeat_for_opts_all_table_types(fun update_counter_with_default_bad_default_do/1).
3077+
3078+
update_counter_with_default_bad_default_do(Opts) ->
3079+
T = ets_new(a, [{keypos, 3} | Opts]),
3080+
0 = ets:info(T, size),
3081+
ok = try ets:update_counter(T, 0, {2, 1}, {0, 0})
3082+
catch
3083+
error:badarg -> ok;
3084+
Class:Reason -> {Class, Reason}
3085+
end,
3086+
0 = ets:info(T, size),
3087+
ok.
3088+
30733089
update_counter_table_growth(_Config) ->
30743090
repeat_for_opts(fun update_counter_table_growth_do/1).
30753091

0 commit comments

Comments
 (0)