diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-15 16:54:06 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-15 16:54:06 +0000 |
commit | ecd58aec08964340b7b74900f806e84392cf6065 (patch) | |
tree | 232cb3c7d0b9b3ca80256a416f4c47e136aef854 /py | |
parent | 6c2455f4810f8dd048a3ff13a233a5f13b556ea4 (diff) | |
download | micropython-ecd58aec08964340b7b74900f806e84392cf6065.tar.gz micropython-ecd58aec08964340b7b74900f806e84392cf6065.zip |
py: Fix bug in vstr_ins_blank_bytes.
Diffstat (limited to 'py')
-rw-r--r-- | py/vstr.c | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -227,11 +227,10 @@ char *vstr_ins_blank_bytes(vstr_t *vstr, uint byte_pos, uint byte_len) { if (!vstr_ensure_extra(vstr, byte_len)) { return NULL; } - // copy up the string to make room for the new bytes - memmove(vstr->buf + l - 1 + byte_len, vstr->buf + l - 1, l - byte_pos); + // copy up the string to make room for the new bytes; +1 for the null byte + memmove(vstr->buf + byte_pos + byte_len, vstr->buf + byte_pos, l - byte_pos + 1); // increase the length vstr->len += byte_len; - vstr->buf[vstr->len] = 0; } return vstr->buf + byte_pos; } @@ -243,9 +242,9 @@ void vstr_ins_byte(vstr_t *vstr, uint byte_pos, byte b) { } } -void vstr_ins_char(vstr_t *vstr, uint pos, unichar chr) { +void vstr_ins_char(vstr_t *vstr, uint char_pos, unichar chr) { // TODO UNICODE - char *s = vstr_ins_blank_bytes(vstr, pos, 1); + char *s = vstr_ins_blank_bytes(vstr, char_pos, 1); if (s != NULL) { *s = chr; } |