summaryrefslogtreecommitdiffstatshomepage
path: root/py/vstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/vstr.c')
-rw-r--r--py/vstr.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/py/vstr.c b/py/vstr.c
index 032acc61bc..4fc4326e23 100644
--- a/py/vstr.c
+++ b/py/vstr.c
@@ -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);