Commit 04d5e644 authored by Damien George's avatar Damien George

py/objarray: Fix array.append so it doesn't extend if append fails.

Addresses issue #1965.
parent 2c915e1a
......@@ -336,7 +336,9 @@ STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) {
self->items = m_renew(byte, self->items, item_sz * self->len, item_sz * (self->len + self->free));
mp_seq_clear(self->items, self->len + 1, self->len + self->free, item_sz);
}
mp_binary_set_val_array(self->typecode, self->items, self->len++, arg);
mp_binary_set_val_array(self->typecode, self->items, self->len, arg);
// only update length/free if set succeeded
self->len++;
self->free--;
return mp_const_none; // return None, as per CPython
}
......
# test bytearray.append method
a = bytearray(4)
print(a)
# append should append a single byte
a.append(2)
print(a)
# a should not be modified if append fails
try:
a.append(None)
except TypeError:
print('TypeError')
print(a)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment