#include "advent.h"
#include "dungeon.h"
-static void* xmalloc(size_t size)
+static void* xcalloc(size_t size)
{
- void* ptr = malloc(size);
+ void* ptr = calloc(size, 1);
if (ptr == NULL) {
// LCOV_EXCL_START
// exclude from coverage analysis because we can't simulate an out of memory error in testing
// Rendered string
ssize_t size = 2000; /* msglen > 50 ? msglen*2 : 100; */
- char* rendered = xmalloc(size);
+ char* rendered = xcalloc(size);
char* renderp = rendered;
// Handle format specifiers (including the custom %S) by
// Unmodified string specifier.
if (msg[i] == 's') {
char *arg = va_arg(ap, char *);
- strncat(renderp, arg, size-1);
+ strncat(renderp, arg, size - 1);
size_t len = strlen(renderp);
renderp += len;
size -= len;
void echo_input(FILE* destination, const char* input_prompt, const char* input)
{
size_t len = strlen(input_prompt) + strlen(input) + 1;
- char* prompt_and_input = (char*) xmalloc(len);
+ char* prompt_and_input = (char*) xcalloc(len);
strcpy(prompt_and_input, input_prompt);
strcat(prompt_and_input, input);
fprintf(destination, "%s\n", prompt_and_input);
continue;
}
- char* firstword = (char*) xmalloc(strlen(reply) + 1);
+ char* firstword = (char*) xcalloc(strlen(reply) + 1);
sscanf(reply, "%s", firstword);
free(reply);
continue;
}
- char* firstword = (char*) xmalloc(strlen(reply) + 1);
+ char* firstword = (char*) xcalloc(strlen(reply) + 1);
sscanf(reply, "%s", firstword);
free(reply);