lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 14 Apr 2011 15:34:05 +0200
From:	Michal Nazarewicz <mina86@...a86.com>
To:	Alexey Dobriyan <adobriyan@...il.com>,
	Andrew Morton <akpm@...ux-foundation.org>
Cc:	linux-kernel@...r.kernel.org
Subject: [PATCH] kstrtox: reuse functions from ctype.h

kstrto*() family of functions uses open coded test
for a hexadecimal digit and own implementation of
tolower() function.  This commit changes the code
to use definitions from ctype.h.

Signed-off-by: Michal Nazarewicz <mina86@...a86.com>
---
 lib/kstrtox.c |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)

Was there a reason not to use code from ctype.h?

I know that ctype.h's tolower() is kinda creepy but
IMO it's still better to reuse.

diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index 05672e8..ba6c0d5 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -18,11 +18,6 @@
 #include <linux/module.h>
 #include <linux/types.h>
 
-static inline char _tolower(const char c)
-{
-	return c | 0x20;
-}
-
 static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
 {
 	unsigned long long acc;
@@ -30,14 +25,14 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
 
 	if (base == 0) {
 		if (s[0] == '0') {
-			if (_tolower(s[1]) == 'x' && isxdigit(s[2]))
+			if (tolower(s[1]) == 'x' && isxdigit(s[2]))
 				base = 16;
 			else
 				base = 8;
 		} else
 			base = 10;
 	}
-	if (base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
+	if (base == 16 && s[0] == '0' && tolower(s[1]) == 'x')
 		s += 2;
 
 	acc = 0;
@@ -47,8 +42,8 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
 
 		if ('0' <= *s && *s <= '9')
 			val = *s - '0';
-		else if ('a' <= _tolower(*s) && _tolower(*s) <= 'f')
-			val = _tolower(*s) - 'a' + 10;
+		else if (isxdigit(*s))
+			val = tolower(*s) - 'a' + 10;
 		else if (*s == '\n') {
 			if (*(s + 1) == '\0')
 				break;
-- 
1.7.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ