diff mbox series

[mmc-utils,1/5] Check calloc's return value before using the pointer

Message ID 20181218143601.24413-2-michael.heimpold@i2se.com (mailing list archive)
State New, archived
Headers show
Series Various fixes for mmc-utils | expand

Commit Message

Michael Heimpold Dec. 18, 2018, 2:35 p.m. UTC
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>
---
 lsmmc.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/lsmmc.c b/lsmmc.c
index 9737b37..e514c83 100644
--- a/lsmmc.c
+++ b/lsmmc.c
@@ -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))