crtdll: Supress sign-extension through integer promotion

Andrew Talbot andrew.talbot at talbotville.com
Wed Sep 21 14:44:03 CDT 2011


Changelog:
    crtdll: Suppress sign-extension through integer promotion.

Because integer promotion takes place before a cast is applied, a (signed) char
with the sign bit set will automatically be promoted to a negative integer
before being cast. Casting such to unsigned int would produce a very large
positive value, so we need to cast to unsigned char to suppress the
sign-extension. (I have left it to the function to implicitly convert the
returned value to unsigned int thereafter.)


diff --git a/dlls/crtdll/crtdll_main.c b/dlls/crtdll/crtdll_main.c
index a09f6f6..ac5677f 100644
--- a/dlls/crtdll/crtdll_main.c
+++ b/dlls/crtdll/crtdll_main.c
@@ -176,7 +176,7 @@ size_t CDECL _strncnt(const char *str, size_t maxlen)
  */
 unsigned int CDECL _strnextc(const char *str)
 {
-    return (unsigned int)str[0];
+    return (unsigned char)str[0];
 }
 
 



More information about the wine-patches mailing list