OSDN Git Service

* miscfuncs.cc (cygwin_strncasecmp): Fix bug which results in
authorcorinna <corinna>
Mon, 14 Jul 2008 19:58:15 +0000 (19:58 +0000)
committercorinna <corinna>
Mon, 14 Jul 2008 19:58:15 +0000 (19:58 +0000)
prematurely truncated strings.  Simplify target length argument to
sys_mbstowcs.

winsup/cygwin/ChangeLog
winsup/cygwin/miscfuncs.cc

index 7bbf33a..0953c18 100644 (file)
@@ -1,5 +1,11 @@
 2008-07-14  Corinna Vinschen  <corinna@vinschen.de>
 
+       * miscfuncs.cc (cygwin_strncasecmp): Fix bug which results in
+       prematurely truncated strings.  Simplify target length argument to
+       sys_mbstowcs.
+
+2008-07-14  Corinna Vinschen  <corinna@vinschen.de>
+
        * autoload.cc (GetExtendedTcpTable): Define.
        * fhandler_socket.cc (address_in_use): Take const struct sockaddr
        pointer as argument.  Implement additional AF_INET6 table check.
index aff357d..845575e 100644 (file)
@@ -130,16 +130,14 @@ cygwin_strncasecmp (const char *cs, const char *ct, size_t n)
 
   while (cs[ls] && ls < n)
     ++ls;
-  len = ls * sizeof (WCHAR);
+  len = (ls + 1) * sizeof (WCHAR);
   RtlInitEmptyUnicodeString (&us, (PWCHAR) alloca (len), len);
-  us.Length = sys_mbstowcs (us.Buffer, us.MaximumLength / sizeof (WCHAR),
-                           cs, ls) * sizeof (WCHAR);
+  us.Length = sys_mbstowcs (us.Buffer, ls + 1, cs, ls) * sizeof (WCHAR);
   while (ct[lt] && lt < n)
     ++lt;
-  len = lt * sizeof (WCHAR);
+  len = (lt + 1) * sizeof (WCHAR);
   RtlInitEmptyUnicodeString (&ut, (PWCHAR) alloca (len), len);
-  ut.Length = sys_mbstowcs (ut.Buffer, ut.MaximumLength / sizeof (WCHAR),
-                           ct, lt)  * sizeof (WCHAR);
+  ut.Length = sys_mbstowcs (ut.Buffer, lt + 1, ct, lt)  * sizeof (WCHAR);
   return RtlCompareUnicodeString (&us, &ut, TRUE);
 }