Skip to content

Commit d135c85

Browse files
juhligMaria-12648430
authored andcommitted
Fix ets:update_element/4
Co-authored-by: Maria Scott <maria-12648430@hnc-agency.org>
1 parent a930c81 commit d135c85

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

erts/emulator/beam/erl_db.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,8 @@ BIF_RETTYPE ets_update_element_4(BIF_ALIST_4)
14071407

14081408
DB_BIF_GET_TABLE(tb, DB_WRITE, LCK_WRITE_REC, BIF_ets_update_element_4);
14091409

1410-
if (is_not_tuple(BIF_ARG_4)) {
1410+
if (is_not_tuple(BIF_ARG_4)
1411+
|| arityval(*tuple_val(BIF_ARG_4)) < tb->common.keypos) {
14111412
db_unlock(tb, LCK_WRITE_REC);
14121413
BIF_ERROR(BIF_P, BADARG);
14131414
}

lib/stdlib/test/ets_SUITE.erl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,6 +2699,13 @@ update_element_default_opts(Opts) ->
26992699
[{key1, key2, b, x}] = ets:lookup(Tab, Key),
27002700
true = ets:update_element(Tab, Key, {3, c}, {key1, key2, a, y}),
27012701
[{key1, key2, c, x}] = ets:lookup(Tab, Key),
2702+
ok = try
2703+
Sz = Pos - 1,
2704+
Obj = list_to_tuple(lists:seq(1, Sz)),
2705+
ets:update_element(Tab, key_not_present, {1, x}, Obj)
2706+
catch
2707+
error:badarg -> ok
2708+
end,
27022709
ets:delete(Tab)
27032710
end
27042711
)

0 commit comments

Comments
 (0)