mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 11:32:48 -05:00
GetDlgItemTextW_alloc: use the right memchr.
When retrieving Unicode text from an edit box in the GUI configurer, we were using plain memchr() to look for a terminating NUL. But of course you have to use wmemchr() to look for a UTF-16 NUL, or else memchr() will generate a false positive on the UTF-16 version of (at least) any ASCII character! (I also have to provide a fallback implementation of wmemchr for the w32old builds, which don't have it in the libc they build against. It's as simple as possible, and we use the libc version where possible.)
This commit is contained in:
@ -4,6 +4,8 @@
|
||||
* string is dynamically allocated; caller must free.
|
||||
*/
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
#include "putty.h"
|
||||
|
||||
char *GetDlgItemText_alloc(HWND hwnd, int id)
|
||||
@ -27,7 +29,7 @@ wchar_t *GetDlgItemTextW_alloc(HWND hwnd, int id)
|
||||
do {
|
||||
sgrowarray_nm(ret, size, size);
|
||||
GetDlgItemTextW(hwnd, id, ret, size);
|
||||
} while (!memchr(ret, '\0', size-1));
|
||||
} while (!wmemchr(ret, L'\0', size-1));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
15
windows/utils/wmemchr.c
Normal file
15
windows/utils/wmemchr.c
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Work around lack of wmemchr in older MSVC libraries.
|
||||
*/
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n)
|
||||
{
|
||||
for (; n != 0; s++, n--)
|
||||
if (*s == c)
|
||||
return (wchar_t *)s;
|
||||
return NULL;
|
||||
}
|
Reference in New Issue
Block a user