aboutsummaryrefslogtreecommitdiff
path: root/py/vstr.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-04-18 14:23:13 +0100
committerDamien George <damien.p.george@gmail.com>2015-04-18 14:23:13 +0100
commit1c9a499135a03a7eabc66e9d3571508fe074e859 (patch)
tree6f82dd8405d905429a06a2c216ccdea293bddb33 /py/vstr.c
parentc1a77a0c9f03cb5e456dcbf3bad7471d6a6383c9 (diff)
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.
Diffstat (limited to 'py/vstr.c')
-rw-r--r--py/vstr.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/py/vstr.c b/py/vstr.c
index 45915e7c4..ba85fa43c 100644
--- a/py/vstr.c
+++ b/py/vstr.c
@@ -244,8 +244,8 @@ void vstr_add_strn(vstr_t *vstr, const char *str, size_t len) {
if (vstr->had_error || !vstr_ensure_extra(vstr, len)) {
// if buf is fixed, we got here because there isn't enough room left
// so just try to copy as much as we can, with room for a possible null byte
- if (vstr->fixed_buf && vstr->len + 1 < vstr->alloc) {
- len = vstr->alloc - vstr->len - 1;
+ if (vstr->fixed_buf && vstr->len < vstr->alloc) {
+ len = vstr->alloc - vstr->len;
goto copy;
}
return;
@@ -325,10 +325,6 @@ void vstr_printf(vstr_t *vstr, const char *fmt, ...) {
}
void vstr_vprintf(vstr_t *vstr, const char *fmt, va_list ap) {
- if (vstr->had_error || !vstr_ensure_extra(vstr, strlen(fmt))) {
- return;
- }
-
mp_print_t print = {vstr, (mp_print_strn_t)vstr_add_strn};
mp_vprintf(&print, fmt, ap);
}