summaryrefslogtreecommitdiffstatshomepage
path: root/py/vstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/vstr.c')
-rw-r--r--py/vstr.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/py/vstr.c b/py/vstr.c
index 181b1c49b9..2e53744362 100644
--- a/py/vstr.c
+++ b/py/vstr.c
@@ -151,7 +151,7 @@ STATIC bool vstr_ensure_extra(vstr_t *vstr, size_t size) {
if (vstr->fixed_buf) {
return false;
}
- size_t new_alloc = ROUND_ALLOC((vstr->len + size) + 64);
+ size_t new_alloc = ROUND_ALLOC((vstr->len + size) + 16);
char *new_buf = m_renew(char, vstr->buf, vstr->alloc, new_alloc);
if (new_buf == NULL) {
vstr->had_error = true;
@@ -181,9 +181,15 @@ char *vstr_add_len(vstr_t *vstr, size_t len) {
// Doesn't increase len, just makes sure there is a null byte at the end
char *vstr_null_terminated_str(vstr_t *vstr) {
- if (vstr->had_error || !vstr_ensure_extra(vstr, 1)) {
+ if (vstr->had_error) {
return NULL;
}
+ // If there's no more room, add single byte
+ if (vstr->alloc == vstr->len) {
+ if (vstr_extend(vstr, 1) == NULL) {
+ return NULL;
+ }
+ }
vstr->buf[vstr->len] = '\0';
return vstr->buf;
}