Check calloc's return value before using the pointer

If calloc fails, bail out immediately instead of trying to
use the NULL pointer.

Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com>
Cc: Michael Heimpold <mhei@heimpold.de>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Chris Ball <chris@printf.net>
This commit is contained in:
Michael Heimpold authored and Chris Ball committed 2019-10-04 20:47:11 -04:00
1 parent d40ec535b9
commit de0715d5b0
1 file changed
+2
+2
View File
@@ -374,6 +374,8 @@ char *to_binstr(char *hexstr)
char *binstr;
binstr = calloc(strlen(hexstr) * 4 + 1, sizeof(char));
if (!binstr)
return NULL;
while (hexstr && *hexstr != '\0') {
if (!isxdigit(*hexstr))