summaryrefslogtreecommitdiffstats
path: root/dstring.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-01-31 23:17:23 -0500
committerTavian Barnes <tavianator@tavianator.com>2019-01-31 23:17:23 -0500
commitdbf435f4555ee3a1f2f7c929866f63dc5a48662b (patch)
tree2a3fac8951868794a50f6a07ab9e0d8f309869e9 /dstring.c
parent2d3b03183c9f1cdb685977f349bf4bbc74a2038d (diff)
downloadbfs-dbf435f4555ee3a1f2f7c929866f63dc5a48662b.tar.xz
dstring: Initialize freshly-allocated strings
Previously, a string allocated with dstralloc() had length 0 but no terminating NUL byte there. This was problematic if such a string was used without being modified. In particular, this was reproducible with bfs -ok by not typing any response to the prompt. In that case, uninitialized memory was being tested for a y/n response, with unpredictable results.
Diffstat (limited to 'dstring.c')
-rw-r--r--dstring.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/dstring.c b/dstring.c
index 98678c0..f4a865a 100644
--- a/dstring.c
+++ b/dstring.c
@@ -43,6 +43,7 @@ char *dstralloc(size_t capacity) {
header->capacity = capacity;
header->length = 0;
+ header->data[0] = '\0';
return header->data;
}