diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-31 17:10:59 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-31 17:10:59 +0100 |
commit | 8cd72bdf92fc8d8d735e332295e9582ae20bbaef (patch) | |
tree | 2f40feb82e3e18d98b4d626ffeb0f068bdd074fc /py | |
parent | 43e92cfb521db55fb2d0001388c0e3a532405b50 (diff) | |
download | micropython-8cd72bdf92fc8d8d735e332295e9582ae20bbaef.tar.gz micropython-8cd72bdf92fc8d8d735e332295e9582ae20bbaef.zip |
py: Fix vstr_init for case that alloc = 0.
Diffstat (limited to 'py')
-rw-r--r-- | py/vstr.c | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -10,6 +10,10 @@ #define ROUND_ALLOC(a) (((a) & ((~0) - 7)) + 8) void vstr_init(vstr_t *vstr, int alloc) { + if (alloc < 2) { + // need at least 1 byte for the null byte at the end + alloc = 2; + } vstr->alloc = alloc; vstr->len = 0; vstr->buf = m_new(char, vstr->alloc); |