diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2019-01-31 23:17:23 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2019-01-31 23:17:23 -0500 |
commit | dbf435f4555ee3a1f2f7c929866f63dc5a48662b (patch) | |
tree | 2a3fac8951868794a50f6a07ab9e0d8f309869e9 | |
parent | 2d3b03183c9f1cdb685977f349bf4bbc74a2038d (diff) | |
download | bfs-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.
-rw-r--r-- | dstring.c | 1 |
1 files changed, 1 insertions, 0 deletions
@@ -43,6 +43,7 @@ char *dstralloc(size_t capacity) { header->capacity = capacity; header->length = 0; + header->data[0] = '\0'; return header->data; } |