From 7244a1443930824b31498cd30f1840af648131c3 Mon Sep 17 00:00:00 2001 From: "John R. Lenton" Date: Sun, 12 Jan 2014 23:37:45 +0000 Subject: oops, nasty off-by-one in set_copy --- py/objset.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'py/objset.c') diff --git a/py/objset.c b/py/objset.c index 2ed2abb611..e41f2c47f4 100644 --- a/py/objset.c +++ b/py/objset.c @@ -27,6 +27,10 @@ static mp_obj_t set_it_iternext(mp_obj_t self_in); void set_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { mp_obj_set_t *self = self_in; + if (self->set.used == 0) { + print(env, "set()"); + return; + } bool first = true; print(env, "{"); for (int i = 0; i < self->set.alloc; i++) { @@ -122,7 +126,7 @@ static mp_obj_t set_copy(mp_obj_t self_in) { mp_obj_set_t *other = m_new_obj(mp_obj_set_t); other->base.type = &set_type; - mp_set_init(&other->set, self->set.alloc); + mp_set_init(&other->set, self->set.alloc - 1); other->set.used = self->set.used; memcpy(other->set.table, self->set.table, self->set.alloc * sizeof(mp_obj_t)); -- cgit v1.2.3