Skip to content

Commit 1c9a499

Browse files
committed
py/vstr.c: Allow vstr_printf to print correctly to a fixed buffer.
This patch allows vstr_printf to use all the available space of a fixed vstr buffer. vstr_printf is a good alternative to snprintf.
1 parent c1a77a0 commit 1c9a499

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

py/vstr.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ void vstr_add_strn(vstr_t *vstr, const char *str, size_t len) {
244244
if (vstr->had_error || !vstr_ensure_extra(vstr, len)) {
245245
// if buf is fixed, we got here because there isn't enough room left
246246
// so just try to copy as much as we can, with room for a possible null byte
247-
if (vstr->fixed_buf && vstr->len + 1 < vstr->alloc) {
248-
len = vstr->alloc - vstr->len - 1;
247+
if (vstr->fixed_buf && vstr->len < vstr->alloc) {
248+
len = vstr->alloc - vstr->len;
249249
goto copy;
250250
}
251251
return;
@@ -325,10 +325,6 @@ void vstr_printf(vstr_t *vstr, const char *fmt, ...) {
325325
}
326326

327327
void vstr_vprintf(vstr_t *vstr, const char *fmt, va_list ap) {
328-
if (vstr->had_error || !vstr_ensure_extra(vstr, strlen(fmt))) {
329-
return;
330-
}
331-
332328
mp_print_t print = {vstr, (mp_print_strn_t)vstr_add_strn};
333329
mp_vprintf(&print, fmt, ap);
334330
}

0 commit comments

Comments
 (0)