diff mbox series

[mmc-utils,v2,3/5] Fix parsing of character in to_binstr()

Message ID 20190912210509.19816-4-mhei@heimpold.de (mailing list archive)
State New, archived
Headers show
Series Various fixes for mmc-utils | expand

Commit Message

Michael Heimpold Sept. 12, 2019, 9:05 p.m. UTC
From: Michael Heimpold <michael.heimpold@i2se.com>

When a hex-digit > 'a' or 'A' is read, we have to add an offset of 10
to access the valid symbol in our mapping table.

Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com>
Cc: Michael Heimpold <mhei@heimpold.de>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
---
 lsmmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lsmmc.c b/lsmmc.c
index a53bc57..e64117c 100644
--- a/lsmmc.c
+++ b/lsmmc.c
@@ -386,9 +386,9 @@  char *to_binstr(char *hexstr)
 		if (isdigit(*hexstr))
 			strcat(binstr, bindigits[*hexstr - '0']);
 		else if (islower(*hexstr))
-			strcat(binstr, bindigits[*hexstr - 'a']);
+			strcat(binstr, bindigits[*hexstr - 'a' + 10]);
 		else
-			strcat(binstr, bindigits[*hexstr - 'A']);
+			strcat(binstr, bindigits[*hexstr - 'A' + 10]);
 
 		hexstr++;
 	}