From 63c32f730a6656170a19a31cbe946cf8ed80b119 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Sun, 17 Mar 2019 00:12:15 +0100 Subject: Add error checking to error formatters --- src/cc4group.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/cc4group.c b/src/cc4group.c index 56d307a..7a550cd 100644 --- a/src/cc4group.c +++ b/src/cc4group.c @@ -133,7 +133,10 @@ static char* cc4group_strerrorFormatter(int32_t const code, const char* const me { (void)data; char* message; - asprintf(&message, "%s: %s: %s (%d)", method, causer, strerror(code), code); + if(asprintf(&message, "%s: %s: %s (%d)", method, causer, strerror(code), code) == -1) + { + return NULL; + } return message; } @@ -152,7 +155,10 @@ static char* cc4group_zerrorFormatter(int32_t const code, const char* const meth if(code == CC4GROUP_MEM_ERROR) { errorString = ""; - asprintf(&message, "%s: %s: Can't allocate memory for copying the input data: %s (%d)", method, causer, strerror(storedErrno), storedErrno); + if(asprintf(&message, "%s: %s: Can't allocate memory for copying the input data: %s (%d)", method, causer, strerror(storedErrno), storedErrno) == -1) + { + return NULL; + } return message; } @@ -169,7 +175,10 @@ static char* cc4group_zerrorFormatter(int32_t const code, const char* const meth errorString = zError(code); } - asprintf(&message, "%s: %s: %s (%d)", method, causer, errorString, code); + if(asprintf(&message, "%s: %s: %s (%d)", method, causer, errorString, code) == -1) + { + return NULL; + } return message; } @@ -179,7 +188,10 @@ static char* cc4group_messageFormatter(int32_t const code, const char* const met (void)data; char* message; - asprintf(&message, "%s: %s", method, causer); + if(asprintf(&message, "%s: %s", method, causer) == -1) + { + return NULL; + } return message; } -- cgit v1.2.3-54-g00ecf