Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
5866-gb_sets-gb_trees-Stricten-tests-for-intege...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 5866-gb_sets-gb_trees-Stricten-tests-for-integers.patch of Package erlang
From 379490e515b2d557e66925286921c86135d19fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org> Date: Wed, 22 Jun 2022 06:38:52 +0200 Subject: [PATCH 6/7] gb_sets, gb_trees: Stricten tests for integers --- lib/stdlib/src/gb_sets.erl | 24 +++++++++++++----------- lib/stdlib/src/gb_trees.erl | 6 +++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/stdlib/src/gb_sets.erl b/lib/stdlib/src/gb_sets.erl index 8dda0d4ee0..93131d1b24 100644 --- a/lib/stdlib/src/gb_sets.erl +++ b/lib/stdlib/src/gb_sets.erl @@ -259,13 +259,13 @@ is_member_1(_, nil) -> Set1 :: set(Element), Set2 :: set(Element). -insert(Key, {S, T}) -> +insert(Key, {S, T}) when is_integer(S), S >= 0 -> S1 = S + 1, {S1, insert_1(Key, T, ?pow(S1, ?p))}. insert_1(Key, {Key1, Smaller, Bigger}, S) when Key < Key1 -> case insert_1(Key, Smaller, ?div2(S)) of - {T1, H1, S1} when is_integer(H1) -> + {T1, H1, S1} when is_integer(H1), is_integer(S1) -> T = {Key1, T1, Bigger}, {H2, S2} = count(Bigger), H = ?mul2(erlang:max(H1, H2)), @@ -282,7 +282,7 @@ insert_1(Key, {Key1, Smaller, Bigger}, S) when Key < Key1 -> end; insert_1(Key, {Key1, Smaller, Bigger}, S) when Key > Key1 -> case insert_1(Key, Bigger, ?div2(S)) of - {T1, H1, S1} when is_integer(H1) -> + {T1, H1, S1} when is_integer(H1), is_integer(S1) -> T = {Key1, Smaller, T1}, {H2, S2} = count(Smaller), H = ?mul2(erlang:max(H1, H2)), @@ -317,7 +317,7 @@ count(nil) -> Set1 :: set(Element), Set2 :: set(Element). -balance({S, T}) -> +balance({S, T}) when is_integer(S), S >= 0 -> {S, balance(T, S)}. balance(T, S) -> @@ -550,9 +550,9 @@ next([]) -> Set2 :: set(Element), Set3 :: set(Element). -union({N1, T1}, {N2, T2}) when N2 < N1 -> +union({N1, T1}, {N2, T2}) when is_integer(N1), is_integer(N2), N2 < N1 -> union(to_list_1(T2), N2, T1, N1); -union({N1, T1}, {N2, T2}) -> +union({N1, T1}, {N2, T2}) when is_integer(N1), is_integer(N2) -> union(to_list_1(T1), N1, T2, N2). %% We avoid the expensive mathematical computations if there is little @@ -633,7 +633,7 @@ push([X | Xs], As) -> push([], As) -> As. -balance_revlist(L, S) -> +balance_revlist(L, S) when is_integer(S) -> {T, _} = balance_revlist_1(L, S), T. @@ -670,9 +670,9 @@ union_list(S, []) -> S. Set2 :: set(Element), Set3 :: set(Element). -intersection({N1, T1}, {N2, T2}) when N2 < N1 -> +intersection({N1, T1}, {N2, T2}) when is_integer(N1), is_integer(N2), N2 < N1 -> intersection(to_list_1(T2), N2, T1, N1); -intersection({N1, T1}, {N2, T2}) -> +intersection({N1, T1}, {N2, T2}) when is_integer(N1), is_integer(N2) -> intersection(to_list_1(T1), N1, T2, N2). intersection(L, _N1, T2, N2) when N2 < 10 -> @@ -770,7 +770,8 @@ subtract(S1, S2) -> Set2 :: set(Element), Set3 :: set(Element). -difference({N1, T1}, {N2, T2}) -> +difference({N1, T1}, {N2, T2}) when is_integer(N1), N1 >= 0, + is_integer(N2), N2 >= 0 -> difference(to_list_1(T1), N1, T2, N2). difference(L, N1, T2, N2) when N2 < 10 -> @@ -820,7 +821,8 @@ difference_2(Xs, [], As, S) -> Set1 :: set(Element), Set2 :: set(Element). -is_subset({N1, T1}, {N2, T2}) -> +is_subset({N1, T1}, {N2, T2}) when is_integer(N1), N1 >= 0, + is_integer(N2), N2 >= 0 -> is_subset(to_list_1(T1), N1, T2, N2). is_subset(L, _N1, T2, N2) when N2 < 10 -> diff --git a/lib/stdlib/src/gb_trees.erl b/lib/stdlib/src/gb_trees.erl index c0cdde012e..2d5d013a25 100644 --- a/lib/stdlib/src/gb_trees.erl +++ b/lib/stdlib/src/gb_trees.erl @@ -279,7 +279,7 @@ insert(Key, Val, {S, T}) when is_integer(S) -> insert_1(Key, Value, {Key1, V, Smaller, Bigger}, S) when Key < Key1 -> case insert_1(Key, Value, Smaller, ?div2(S)) of - {T1, H1, S1} -> + {T1, H1, S1} when is_integer(H1), is_integer(S1) -> T = {Key1, V, T1, Bigger}, {H2, S2} = count(Bigger), H = ?mul2(erlang:max(H1, H2)), @@ -296,7 +296,7 @@ insert_1(Key, Value, {Key1, V, Smaller, Bigger}, S) when Key < Key1 -> end; insert_1(Key, Value, {Key1, V, Smaller, Bigger}, S) when Key > Key1 -> case insert_1(Key, Value, Bigger, ?div2(S)) of - {T1, H1, S1} -> + {T1, H1, S1} when is_integer(H1), is_integer(S1) -> T = {Key1, V, Smaller, T1}, {H2, S2} = count(Smaller), H = ?mul2(erlang:max(H1, H2)), @@ -349,7 +349,7 @@ count(nil) -> Tree1 :: tree(Key, Value), Tree2 :: tree(Key, Value). -balance({S, T}) -> +balance({S, T}) when is_integer(S), S >= 0 -> {S, balance(T, S)}. balance(T, S) -> -- 2.35.3
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