From dbf435f4555ee3a1f2f7c929866f63dc5a48662b Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 31 Jan 2019 23:17:23 -0500 Subject: 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. --- dstring.c | 1 + 1 file changed, 1 insertion(+) (limited to 'dstring.c') 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; } -- cgit v1.2.3