[PATCH 2/2] lib/strtox: remove unnecessary islower()

Sascha Hauer s.hauer at pengutronix.de
Mon Apr 10 23:39:34 PDT 2017


toupper() does the right thing, no need to test for islower()
beforehand, so

islower(*cp) ? toupper(*cp) : *cp

can be simplified to:

toupper(*cp)

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 lib/strtox.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lib/strtox.c b/lib/strtox.c
index 45aa06bacc..3bb6b0ef89 100644
--- a/lib/strtox.c
+++ b/lib/strtox.c
@@ -20,8 +20,8 @@ unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base)
 	if (!base)
 		base = 10;
 
-	while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp - '0' : (islower(*cp)
-	    ? toupper(*cp) : *cp) - 'A' + 10) < base) {
+	while (isxdigit(*cp) && (value = isdigit(*cp) ?
+	       *cp - '0' : toupper(*cp) - 'A' + 10) < base) {
 		result = result * base + value;
 		cp++;
 	}
@@ -61,9 +61,8 @@ unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int bas
 	if (!base)
 		base = 10;
 
-	while (isxdigit(*cp) && (value = isdigit(*cp)
-				? *cp - '0'
-				: (islower(*cp) ? toupper(*cp) : *cp) - 'A' + 10) < base) {
+	while (isxdigit(*cp) && (value = isdigit(*cp) ?
+	       *cp - '0' : toupper(*cp) - 'A' + 10) < base) {
 		result = result * base + value;
 		cp++;
 	}
-- 
2.11.0




More information about the barebox mailing list