summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorJohn R. Lenton <jlenton@gmail.com>2014-01-12 23:37:45 +0000
committerJohn R. Lenton <jlenton@gmail.com>2014-01-12 23:37:45 +0000
commit7244a1443930824b31498cd30f1840af648131c3 (patch)
tree0b84a6f598ab8d03d98c38eea2f1a89ca0254f3b /py
parentbe790f94d5c66b96aa99b09a83639507f037f0a3 (diff)
downloadmicropython-7244a1443930824b31498cd30f1840af648131c3.tar.gz
micropython-7244a1443930824b31498cd30f1840af648131c3.zip
oops, nasty off-by-one in set_copy
Diffstat (limited to 'py')
-rw-r--r--py/objset.c6
1 files changed, 5 insertions, 1 deletions
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));