]> xenbits.xensource.com Git - people/pauldu/xenbus.git/commitdiff
Don't use C runtime versions of toupper() and tolower()
authorPaul Durrant <paul.durrant@citrix.com>
Thu, 10 Dec 2015 10:37:07 +0000 (10:37 +0000)
committerPaul Durrant <paul.durrant@citrix.com>
Thu, 10 Dec 2015 10:37:07 +0000 (10:37 +0000)
It seems that, despite their trivial functionality, the runtime
implementation insists on converting to Unicode! This means those functions
are actually only safe at PASSIVE_LEVEL.
This patch implements __toupper() and __tolower() as replacements with
no such hidden nastiness and modifies callers to use those.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
src/common/util.h
src/xen/module.c
src/xenbus/fdo.c

index 1a2bb86665a791b081b7922ab88e8ad08f56ccfe..c772b1e1b9ead55696179e0d09934ca8a8741ec9 100644 (file)
@@ -278,4 +278,26 @@ __strtok_r(
     return Token;
 }
 
+static FORCEINLINE CHAR
+__toupper(
+    IN  CHAR    Character
+    )
+{
+    if (Character < 'a' || Character > 'z')
+        return Character;
+
+    return 'A' + Character - 'a';
+}
+
+static FORCEINLINE CHAR
+__tolower(
+    IN  CHAR    Character
+    )
+{
+    if (Character < 'A' || Character > 'Z')
+        return Character;
+
+    return 'a' + Character - 'A';
+}
+
 #endif  // _COMMON_UTIL_H
index ed8838a293d1314990348a72cbe17296074a9932..a5bf3c707b11ff004a5c4b00b791000e54e063b4 100644 (file)
@@ -155,7 +155,7 @@ ModuleAdd(
         if (Name[Index] == '\0')
             break;
 
-        New->Name[Index] = (CHAR)tolower(Name[Index]);
+        New->Name[Index] = __tolower(Name[Index]);
     }
 
     New->Start = Start;
index 00801c9811e224fc0f575eb6b9f2f31ef193cbc0..d079928a3af44a61fd2839c16fc310a505e139ea 100644 (file)
@@ -1129,7 +1129,7 @@ FdoMultiSzToUpcaseAnsi(
             if (Buffer[Index] == '\0')
                 break;
         } else {
-            Buffer[Index] = (CHAR)toupper(Buffer[Index]);
+            Buffer[Index] = __toupper(Buffer[Index]);
             Index++;
         }
     }