From b2487c17eb60424e1cb4a74e4763f057ebbf7f39 Mon Sep 17 00:00:00 2001 From: Jacek Caban <jacek@codeweavers.com> Date: Mon, 12 Oct 2020 18:26:43 +0200 Subject: [PATCH] conhost: Store title as zero terminated string. To make it usable for Windows functions. Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org> --- programs/conhost/conhost.c | 19 ++++++++++--------- programs/conhost/conhost.h | 1 - 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/programs/conhost/conhost.c b/programs/conhost/conhost.c index 934b0a4ce1d..c917b08dc03 100644 --- a/programs/conhost/conhost.c +++ b/programs/conhost/conhost.c @@ -2271,12 +2271,12 @@ static NTSTATUS set_console_title( struct console *console, const WCHAR *in_titl if (size) { - if (!(title = malloc( size ))) return STATUS_NO_MEMORY; + if (!(title = malloc( size + sizeof(WCHAR) ))) return STATUS_NO_MEMORY; memcpy( title, in_title, size ); + title[size / sizeof(WCHAR)] = 0; } free( console->title ); - console->title = title; - console->title_len = size; + console->title = title; if (console->tty_output) { @@ -2284,9 +2284,11 @@ static NTSTATUS set_console_title( struct console *console, const WCHAR *in_titl char *vt; tty_write( console, "\x1b]0;", 4 ); - len = WideCharToMultiByte( get_tty_cp( console ), 0, console->title, size / sizeof(WCHAR), NULL, 0, NULL, NULL); + len = WideCharToMultiByte( get_tty_cp( console ), 0, console->title, size / sizeof(WCHAR), + NULL, 0, NULL, NULL); if ((vt = tty_alloc_buffer( console, len ))) - WideCharToMultiByte( get_tty_cp( console ), 0, console->title, size / sizeof(WCHAR), vt, len, NULL, NULL ); + WideCharToMultiByte( get_tty_cp( console ), 0, console->title, size / sizeof(WCHAR), + vt, len, NULL, NULL ); tty_write( console, "\x07", 1 ); tty_sync( console ); } @@ -2503,10 +2505,9 @@ static NTSTATUS console_input_ioctl( struct console *console, unsigned int code, { WCHAR *result; if (in_size) return STATUS_INVALID_PARAMETER; - TRACE( "returning title %s\n", debugstr_wn(console->title, - console->title_len / sizeof(WCHAR)) ); - if (!(result = alloc_ioctl_buffer( *out_size = min( *out_size, console->title_len )))) - return STATUS_NO_MEMORY; + TRACE( "returning title %s\n", debugstr_w(console->title) ); + *out_size = min( *out_size, console->title ? wcslen( console->title ) * sizeof(WCHAR) : 0 ); + if (!(result = alloc_ioctl_buffer( *out_size ))) return STATUS_NO_MEMORY; if (*out_size) memcpy( result, console->title, *out_size ); return STATUS_SUCCESS; } diff --git a/programs/conhost/conhost.h b/programs/conhost/conhost.h index 322c677b915..7bc102b0df0 100644 --- a/programs/conhost/conhost.h +++ b/programs/conhost/conhost.h @@ -88,7 +88,6 @@ struct console struct edit_line edit_line; /* edit line context */ struct console_window *window; WCHAR *title; /* console title */ - size_t title_len; /* length of console title */ struct history_line **history; /* lines history */ unsigned int history_size; /* number of entries in history array */ unsigned int history_index; /* number of used entries in history array */ -- GitLab