summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>2014-04-02 07:33:47 +0200
committerJérémie Courrèges-Anglas <jca@wxcvbn.org>2014-04-02 07:33:47 +0200
commitbca76d995713e52327663aecdfa93f5d9ac447a1 (patch)
tree96a840ce930cedd3d4313471bc296c7c566b2d01
parentf9d4a134f566b561c9c771166de2139c7ebb8c9d (diff)
downloadratpoison-bca76d995713e52327663aecdfa93f5d9ac447a1.zip
Make sbuf_printf update the len and maxsz internal fields
* sbuf_printf updated the .data field with a freshly allocated string, but didn't bother setting the .len and .maxsz fields of the sbuf. Calling other sbuf_* functions on the same sbuf could lead to erratic behavior and data corruption. eg. in init_screen, the screen's display_string ended up corrupted, using putenv ratpoison couldn't override the DISPLAY environment variable in child processes anymore, introducing a regression on multi-screen setups. Bug reported and cause tracked down by William Yodlowsky, the maintainer of the OpenBSD ratpoison port. Thanks!
-rw-r--r--src/sbuf.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/sbuf.c b/src/sbuf.c
index 77b8a04..661ec83 100644
--- a/src/sbuf.c
+++ b/src/sbuf.c
@@ -123,6 +123,9 @@ sbuf_printf (struct sbuf *b, char *fmt, ...)
b->data = xvsprintf (fmt, ap);
va_end (ap);
+ b->len = strlen (b->data);
+ b->maxsz = b->len + 1;
+
return b->data;
}