From: Paul Durrant Date: Thu, 10 Dec 2015 10:37:07 +0000 (+0000) Subject: Don't use C runtime versions of toupper() and tolower() X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=89876fbdf6a2cd74397e32849a29751157c4a18a;p=people%2Fpauldu%2Fxenbus.git Don't use C runtime versions of toupper() and tolower() 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 --- diff --git a/src/common/util.h b/src/common/util.h index 1a2bb86..c772b1e 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -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 diff --git a/src/xen/module.c b/src/xen/module.c index ed8838a..a5bf3c7 100644 --- a/src/xen/module.c +++ b/src/xen/module.c @@ -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; diff --git a/src/xenbus/fdo.c b/src/xenbus/fdo.c index 00801c9..d079928 100644 --- a/src/xenbus/fdo.c +++ b/src/xenbus/fdo.c @@ -1129,7 +1129,7 @@ FdoMultiSzToUpcaseAnsi( if (Buffer[Index] == '\0') break; } else { - Buffer[Index] = (CHAR)toupper(Buffer[Index]); + Buffer[Index] = __toupper(Buffer[Index]); Index++; } }