* miscfuncs.cc (cygwin_wcsncasecmp): Never access more than n
characters. (cygwin_strncasecmp): Ditto. Fix for strings longer than n.
This commit is contained in:
parent
c69d873f31
commit
301d14d242
|
@ -1,3 +1,9 @@
|
||||||
|
2008-02-01 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* miscfuncs.cc (cygwin_wcsncasecmp): Never access more than n
|
||||||
|
characters.
|
||||||
|
(cygwin_strncasecmp): Ditto. Fix for strings longer than n.
|
||||||
|
|
||||||
2008-02-01 Corinna Vinschen <corinna@vinschen.de>
|
2008-02-01 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* string.h: Re-enable inline strcasematch and strncasematch
|
* string.h: Re-enable inline strcasematch and strncasematch
|
||||||
|
|
|
@ -17,6 +17,8 @@ details. */
|
||||||
#include <alloca.h>
|
#include <alloca.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
#include <winbase.h>
|
||||||
|
#include <winnls.h>
|
||||||
#include "cygthread.h"
|
#include "cygthread.h"
|
||||||
#include "cygtls.h"
|
#include "cygtls.h"
|
||||||
#include "ntdll.h"
|
#include "ntdll.h"
|
||||||
|
@ -94,14 +96,14 @@ extern "C" int __stdcall
|
||||||
cygwin_wcsncasecmp (const wchar_t *ws, const wchar_t *wt, size_t n)
|
cygwin_wcsncasecmp (const wchar_t *ws, const wchar_t *wt, size_t n)
|
||||||
{
|
{
|
||||||
UNICODE_STRING us, ut;
|
UNICODE_STRING us, ut;
|
||||||
|
size_t ls = 0, lt = 0;
|
||||||
|
|
||||||
n *= sizeof (WCHAR);
|
while (ws[ls] && ls < n)
|
||||||
RtlInitUnicodeString (&us, ws);
|
++ls;
|
||||||
if (us.Length > n)
|
RtlInitCountedUnicodeString (&us, ws, ls * sizeof (WCHAR));
|
||||||
us.Length = n;
|
while (wt[lt] && lt < n)
|
||||||
RtlInitUnicodeString (&ut, wt);
|
++lt;
|
||||||
if (ut.Length > n)
|
RtlInitCountedUnicodeString (&ut, wt, lt * sizeof (WCHAR));
|
||||||
ut.Length = n;
|
|
||||||
return RtlCompareUnicodeString (&us, &ut, TRUE);
|
return RtlCompareUnicodeString (&us, &ut, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,18 +127,20 @@ cygwin_strncasecmp (const char *cs, const char *ct, size_t n)
|
||||||
{
|
{
|
||||||
UNICODE_STRING us, ut;
|
UNICODE_STRING us, ut;
|
||||||
ULONG len;
|
ULONG len;
|
||||||
|
size_t ls = 0, lt = 0;
|
||||||
n *= sizeof (WCHAR);
|
|
||||||
len = (strlen (cs) + 1) * sizeof (WCHAR);
|
while (cs[ls] && ls < n)
|
||||||
|
++ls;
|
||||||
|
len = ls * sizeof (WCHAR);
|
||||||
RtlInitEmptyUnicodeString (&us, (PWCHAR) alloca (len), len);
|
RtlInitEmptyUnicodeString (&us, (PWCHAR) alloca (len), len);
|
||||||
us.Length = sys_mbstowcs (us.Buffer, cs, us.MaximumLength) * sizeof (WCHAR);
|
us.Length = MultiByteToWideChar (get_cp (), 0, cs, ls, us.Buffer,
|
||||||
if (us.Length > n)
|
us.MaximumLength) * sizeof (WCHAR);
|
||||||
us.Length = n;
|
while (ct[lt] && lt < n)
|
||||||
len = (strlen (ct) + 1) * sizeof (WCHAR);
|
++lt;
|
||||||
|
len = lt * sizeof (WCHAR);
|
||||||
RtlInitEmptyUnicodeString (&ut, (PWCHAR) alloca (len), len);
|
RtlInitEmptyUnicodeString (&ut, (PWCHAR) alloca (len), len);
|
||||||
ut.Length = sys_mbstowcs (ut.Buffer, ct, ut.MaximumLength) * sizeof (WCHAR);
|
ut.Length = MultiByteToWideChar (get_cp (), 0, ct, lt, ut.Buffer,
|
||||||
if (ut.Length > n)
|
ut.MaximumLength) * sizeof (WCHAR);
|
||||||
ut.Length = n;
|
|
||||||
return RtlCompareUnicodeString (&us, &ut, TRUE);
|
return RtlCompareUnicodeString (&us, &ut, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue