From bc133aa9f1e778745bb994779cd8a4c9efe944b1 Mon Sep 17 00:00:00 2001 From: Laurin Date: Fri, 2 Feb 2024 20:31:28 +0100 Subject: [PATCH] refactoring: handled possible memory allocation errors in both convert functions --- src/conversionOfNumbers/conversionOfNumbers.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/conversionOfNumbers/conversionOfNumbers.c b/src/conversionOfNumbers/conversionOfNumbers.c index 305d0ad..fadc59a 100644 --- a/src/conversionOfNumbers/conversionOfNumbers.c +++ b/src/conversionOfNumbers/conversionOfNumbers.c @@ -24,6 +24,7 @@ char* convertIntToBinaryStr(int input){ int length = binaryStrLen(input); int rest; char* result = (char*)malloc(sizeof(char) * length + 1); + if(result == NULL) return NULL; if(input < 0){ result[0] = '-'; input *= -1; @@ -67,6 +68,7 @@ char* convertIntToHex(int input){ int length = hexStrLen(input); int rest; char* result = (char*)malloc(sizeof(char) * length + 1); + if(result == NULL) return NULL; result[length] = '\0'; do{ rest = input % 16;