Skip to content

Commit 8cd72bd

Browse files
committed
py: Fix vstr_init for case that alloc = 0.
1 parent 43e92cf commit 8cd72bd

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

py/vstr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#define ROUND_ALLOC(a) (((a) & ((~0) - 7)) + 8)
1111

1212
void vstr_init(vstr_t *vstr, int alloc) {
13+
if (alloc < 2) {
14+
// need at least 1 byte for the null byte at the end
15+
alloc = 2;
16+
}
1317
vstr->alloc = alloc;
1418
vstr->len = 0;
1519
vstr->buf = m_new(char, vstr->alloc);

0 commit comments

Comments
 (0)