Nmap Development mailing list archives

[PATCH] Only call tolower on letters in hex2char() in utils.cc


From: Kris Katterjohn <kjak () ispwest com>
Date: Sat, 11 Mar 2006 11:18:43 -0600

The attached patch, other than making hex2char() slightly more readable, makes
it so that tolower() is only called if 'a' or 'b' are letters.

Thanks,
Kris
--- utils.cc.orig       2006-03-05 18:00:03.000000000 -0600
+++ utils.cc    2006-03-11 11:11:18.000000000 -0600
@@ -487,16 +487,19 @@ long tval2msecs(char *tspec) {
 static unsigned char hex2char(unsigned char a, unsigned char b)
 {
   int val;
-  if (!isxdigit(a) || !isxdigit(b)) return 0;
-  a = tolower(a);
-  b = tolower(b);
+
+  if (!isxdigit(a) || !isxdigit(b))
+    return 0;
+
   if (isdigit(a))
     val = (a - '0') << 4;
-  else val = (10 + (a - 'a')) << 4;
+  else
+    val = (10 + (tolower(a) - 'a')) << 4;
 
   if (isdigit(b))
     val += (b - '0');
-  else val += 10 + (b - 'a');
+  else
+    val += 10 + (tolower(b) - 'a');
 
   return (unsigned char) val;
 }


_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev

Current thread: