diff --git a/base/error.c b/base/error.c index 4a9871919..91c660be8 100644 --- a/base/error.c +++ b/base/error.c @@ -92,12 +92,17 @@ heim_error_t heim_error_createv(int error_code, const char *fmt, va_list ap) { heim_error_t e; - char *str = NULL; + char *str; int len; - len = vasprintf(&str, fmt, ap); - if (len < 0 || str == NULL) + str = malloc(1024); + if (str == NULL) + return NULL; + len = vsnprintf(str, 1024, fmt, ap); + if (len < 0) { + free(str); return NULL; + } e = _heim_alloc_object(&_heim_error_object, sizeof(struct heim_error)); if (e) {