1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-04-01 19:20:13 -05:00

Merge GetDlgItemTextW_alloc fix from 'pre-0.83'.

This commit is contained in:
Simon Tatham 2025-01-13 20:50:02 +00:00
commit ce7a451d6e
6 changed files with 28 additions and 1 deletions

View File

@ -15,6 +15,7 @@
#cmakedefine01 HAVE_GETNAMEDPIPECLIENTPROCESSID
#cmakedefine01 HAVE_SETDEFAULTDLLDIRECTORIES
#cmakedefine01 HAVE_STRTOUMAX
#cmakedefine01 HAVE_WMEMCHR
#cmakedefine01 HAVE_DWMAPI_H
#cmakedefine NOT_X_WINDOWS

View File

@ -53,6 +53,7 @@ define_negation(NO_HTMLHELP HAVE_HTMLHELP_H)
check_include_files("winsock2.h;afunix.h" HAVE_AFUNIX_H)
check_symbol_exists(strtoumax "inttypes.h" HAVE_STRTOUMAX)
check_symbol_exists(wmemchr "wchar.h" HAVE_WMEMCHR)
check_symbol_exists(AddDllDirectory "windows.h" HAVE_ADDDLLDIRECTORY)
check_symbol_exists(SetDefaultDllDirectories "windows.h"
HAVE_SETDEFAULTDLLDIRECTORIES)

5
defs.h
View File

@ -53,6 +53,11 @@ uintmax_t strtoumax(const char *nptr, char **endptr, int base);
#define SIZEu "zu"
#endif
#if !HAVE_WMEMCHR
/* Work around lack of wmemchr in older MSVC */
wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n);
#endif
#if defined __GNUC__ || defined __clang__
/*
* On MinGW, the correct compiler format checking for vsnprintf() etc

View File

@ -42,6 +42,9 @@ add_sources_from_current_dir(utils
if(NOT HAVE_STRTOUMAX)
add_sources_from_current_dir(utils utils/strtoumax.c)
endif()
if(NOT HAVE_WMEMCHR)
add_sources_from_current_dir(utils utils/wmemchr.c)
endif()
add_sources_from_current_dir(eventloop
cliloop.c handle-wait.c)
add_sources_from_current_dir(console

View File

@ -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
View 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;
}