aboutsummaryrefslogtreecommitdiffstats
path: root/erts
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2014-01-13 22:16:40 +0100
committerBjörn-Egil Dahlberg <[email protected]>2014-01-29 11:08:45 +0100
commitf321ea89fecdb343e58e2485c057326d08fed69c (patch)
treef9ed6f03d30b2b2d570f005e02a78a86fae93516 /erts
parentb8a7203f04a1ed6d2756e6b782cd4c95a8c7c491 (diff)
downloadotp-f321ea89fecdb343e58e2485c057326d08fed69c.tar.gz
otp-f321ea89fecdb343e58e2485c057326d08fed69c.tar.bz2
otp-f321ea89fecdb343e58e2485c057326d08fed69c.zip
erts: Do not allow map iterator created without map
Diffstat (limited to 'erts')
-rw-r--r--erts/emulator/beam/erl_nif.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/erts/emulator/beam/erl_nif.c b/erts/emulator/beam/erl_nif.c
index 1eca7822eb..ca82590a78 100644
--- a/erts/emulator/beam/erl_nif.c
+++ b/erts/emulator/beam/erl_nif.c
@@ -1725,21 +1725,27 @@ int enif_map_iterator_create(ErlNifEnv *env,
}
error:
+#ifdef DEBUG
iter->map = THE_NON_VALUE;
+#endif
return 0;
}
void enif_map_iterator_destroy(ErlNifEnv *env, ErlNifMapIterator *iter)
{
/* not used */
+#ifdef DEBUG
+ iter->map = THE_NON_VALUE;
+#endif
+
}
int enif_map_iterator_is_tail(ErlNifEnv *env, ErlNifMapIterator *iter)
{
+ ASSERT(iter && is_map(iter->map));
ASSERT(iter->idx >= 0 && (iter->idx <= map_get_size(map_val(iter->map)) + 1));
- if (is_map(iter->map) && (
- (iter->t_limit - iter->h_limit) == 1 ||
- iter->idx == iter->t_limit)) {
+ if ((iter->t_limit - iter->h_limit) == 1
+ || iter->idx == iter->t_limit) {
return 1;
}
return 0;
@@ -1747,10 +1753,10 @@ int enif_map_iterator_is_tail(ErlNifEnv *env, ErlNifMapIterator *iter)
int enif_map_iterator_is_head(ErlNifEnv *env, ErlNifMapIterator *iter)
{
+ ASSERT(iter && is_map(iter->map));
ASSERT(iter->idx >= 0 && (iter->idx <= map_get_size(map_val(iter->map)) + 1));
- if (is_map(iter->map) && (
- (iter->t_limit - iter->h_limit) == 1 ||
- iter->idx == iter->h_limit)) {
+ if ((iter->t_limit - iter->h_limit) == 1
+ || iter->idx == iter->h_limit) {
return 1;
}
return 0;
@@ -1759,7 +1765,8 @@ int enif_map_iterator_is_head(ErlNifEnv *env, ErlNifMapIterator *iter)
int enif_map_iterator_next(ErlNifEnv *env, ErlNifMapIterator *iter)
{
- if (is_map(iter->map) && iter->idx < iter->t_limit) {
+ ASSERT(iter && is_map(iter->map));
+ if (iter->idx < iter->t_limit) {
iter->idx++;
if (iter->idx != iter->t_limit) {
iter->ks++;
@@ -1772,7 +1779,8 @@ int enif_map_iterator_next(ErlNifEnv *env, ErlNifMapIterator *iter)
int enif_map_iterator_prev(ErlNifEnv *env, ErlNifMapIterator *iter)
{
- if (is_map(iter->map) && iter->idx > iter->h_limit ) {
+ ASSERT(iter && is_map(iter->map));
+ if (iter->idx > iter->h_limit ) {
iter->idx--;
if (iter->idx != iter->h_limit ) {
iter->ks--;
@@ -1788,7 +1796,8 @@ int enif_map_iterator_get_pair(ErlNifEnv *env,
Eterm *key,
Eterm *value)
{
- if (is_map(iter->map) && iter->idx > iter->h_limit && iter->idx < iter->t_limit) {
+ ASSERT(iter && is_map(iter->map));
+ if (iter->idx > iter->h_limit && iter->idx < iter->t_limit) {
ASSERT(iter->ks >= map_get_keys(map_val(iter->map)) &&
iter->ks < (map_get_keys(map_val(iter->map)) + map_get_size(map_val(iter->map))));
ASSERT(iter->vs >= map_get_values(map_val(iter->map)) &&