Alexandre Julliard : server: Store length of window text instead of null-terminating it.
Alexandre Julliard
julliard at winehq.org
Mon Mar 23 15:47:09 CDT 2020
Module: wine
Branch: master
Commit: a88973a5f969eaa0ba0788c52977dd5100a80dad
URL: https://source.winehq.org/git/wine.git/?a=commit;h=a88973a5f969eaa0ba0788c52977dd5100a80dad
Author: Alexandre Julliard <julliard at winehq.org>
Date: Sat Mar 21 11:40:18 2020 +0100
server: Store length of window text instead of null-terminating it.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
server/window.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/server/window.c b/server/window.c
index c9b131cba5..3a88b7f34f 100644
--- a/server/window.c
+++ b/server/window.c
@@ -88,6 +88,7 @@ struct window
DPI_AWARENESS dpi_awareness; /* DPI awareness mode */
lparam_t user_data; /* user-specific data */
WCHAR *text; /* window caption text */
+ data_size_t text_len; /* length of window caption */
unsigned int paint_flags; /* various painting flags */
int prop_inuse; /* number of in-use window properties */
int prop_alloc; /* number of allocated window properties */
@@ -506,6 +507,7 @@ static struct window *create_window( struct window *parent, struct window *owner
win->dpi = 0;
win->user_data = 0;
win->text = NULL;
+ win->text_len = 0;
win->paint_flags = 0;
win->prop_inuse = 0;
win->prop_alloc = 0;
@@ -2407,10 +2409,10 @@ DECL_HANDLER(get_window_text)
{
struct window *win = get_window( req->handle );
- if (win && win->text)
+ if (win && win->text_len)
{
- reply->length = strlenW( win->text );
- set_reply_data( win->text, min( reply->length * sizeof(WCHAR), get_reply_max_size() ));
+ reply->length = win->text_len / sizeof(WCHAR);
+ set_reply_data( win->text, min( win->text_len, get_reply_max_size() ));
}
}
@@ -2418,21 +2420,16 @@ DECL_HANDLER(get_window_text)
/* set the window text */
DECL_HANDLER(set_window_text)
{
+ data_size_t len;
+ WCHAR *text = NULL;
struct window *win = get_window( req->handle );
- if (win)
- {
- WCHAR *text = NULL;
- data_size_t len = get_req_data_size() / sizeof(WCHAR);
- if (len)
- {
- if (!(text = mem_alloc( (len+1) * sizeof(WCHAR) ))) return;
- memcpy( text, get_req_data(), len * sizeof(WCHAR) );
- text[len] = 0;
- }
- free( win->text );
- win->text = text;
- }
+ if (!win) return;
+ len = (get_req_data_size() / sizeof(WCHAR)) * sizeof(WCHAR);
+ if (len && !(text = memdup( get_req_data(), len ))) return;
+ free( win->text );
+ win->text = text;
+ win->text_len = len;
}
More information about the wine-cvs
mailing list