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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Michael Heimpold <michael.heimpold@xxxxxxxx>
Cc: Michael Heimpold <mhei@xxxxxxxxxxx>
---
 lsmmc.c | 2 ++
 1 file changed, 2 insertions(+)

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))
-- 
2.17.1




[Index of Archives]     [Linux Memonry Technology]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux