From a45a7f5d1aeed7845f56cf56382c625445fbb583 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 24 Sep 2014 10:31:11 +0300 Subject: [PATCH] Fix bug #18528 with crashes at startup during frameset restoration. src/w32term.c (w32_read_socket): Don't use frame dimensions for resizing if GetClientRect returned an empty (0, 0, 0, 0) rectangle. Check the return value of GetClientRect, and don't use the results if it didn't succeed. src/dispnew.c (change_frame_size_1): Recompute the frame dimensions in columns and lines after correcting the pixel dimensions in check_frame_size. (adjust_decode_mode_spec_buffer): Add assertion to avoid passing negative values to xrealloc. --- src/ChangeLog | 13 +++++++++++ src/dispnew.c | 15 ++++++++----- src/w32term.c | 62 +++++++++++++++++++++++++++++---------------------- 3 files changed, 58 insertions(+), 32 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 4d969d73279..a5c25ab7168 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2014-09-24 Eli Zaretskii + + * w32term.c (w32_read_socket): Don't use frame dimensions for + resizing if GetClientRect returned an empty (0, 0, 0, 0) + rectangle. Check the return value of GetClientRect, and don't use + the results if it didn't succeed. + + * dispnew.c (change_frame_size_1): Recompute the frame dimensions + in columns and lines after correcting the pixel dimensions in + check_frame_size. + (adjust_decode_mode_spec_buffer): Add assertion to avoid passing + negative values to xrealloc. (Bug#18528) + 2014-09-22 Dmitry Antipov On OSX, do not free font-specific data more than once (Bug#18501). diff --git a/src/dispnew.c b/src/dispnew.c index 5bdcb279be7..71345775045 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -2138,8 +2138,11 @@ adjust_frame_glyphs_for_window_redisplay (struct frame *f) static void adjust_decode_mode_spec_buffer (struct frame *f) { + ssize_t frame_message_buf_size = FRAME_MESSAGE_BUF_SIZE (f); + + eassert (frame_message_buf_size >= 0); f->decode_mode_spec_buffer = xrealloc (f->decode_mode_spec_buffer, - FRAME_MESSAGE_BUF_SIZE (f) + 1); + frame_message_buf_size + 1); } @@ -5539,10 +5542,6 @@ change_frame_size_1 (struct frame *f, int new_width, int new_height, { new_text_width = (new_width == 0) ? FRAME_TEXT_WIDTH (f) : new_width; new_text_height = (new_height == 0) ? FRAME_TEXT_HEIGHT (f) : new_height; - /* Consider rounding here: Currently, the root window can be - larger than the frame in terms of columns/lines. */ - new_cols = new_text_width / FRAME_COLUMN_WIDTH (f); - new_lines = new_text_height / FRAME_LINE_HEIGHT (f); } else { @@ -5555,6 +5554,12 @@ change_frame_size_1 (struct frame *f, int new_width, int new_height, /* Compute width of windows in F. */ /* Round up to the smallest acceptable size. */ check_frame_size (f, &new_text_width, &new_text_height, 1); + /* Recompute the dimensions in character units, since + check_frame_size might have changed the pixel dimensions. */ + /* Consider rounding here: Currently, the root window can be + larger than the frame in terms of columns/lines. */ + new_cols = new_text_width / FRAME_COLUMN_WIDTH (f); + new_lines = new_text_height / FRAME_LINE_HEIGHT (f); /* This is the width of the frame without vertical scroll bars and fringe columns. Do this after rounding - see discussion of diff --git a/src/w32term.c b/src/w32term.c index 5f15798eeeb..5a053b4fc0d 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -4754,34 +4754,42 @@ w32_read_socket (struct terminal *terminal, RECT rect; int rows, columns, width, height, text_width, text_height; - GetClientRect (msg.msg.hwnd, &rect); - - height = rect.bottom - rect.top; - width = rect.right - rect.left; - text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, width); - text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, height); - rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height); - columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width); - - /* TODO: Clip size to the screen dimensions. */ - - /* Even if the number of character rows and columns has - not changed, the font size may have changed, so we need - to check the pixel dimensions as well. */ - - if (width != FRAME_PIXEL_WIDTH (f) - || height != FRAME_PIXEL_HEIGHT (f) - || text_width != FRAME_TEXT_WIDTH (f) - || text_height != FRAME_TEXT_HEIGHT (f)) + if (GetClientRect (msg.msg.hwnd, &rect) + /* GetClientRect evidently returns (0, 0, 0, 0) if + called on a minimized frame. Such "dimensions" + aren't useful anyway. */ + && !(rect.bottom == 0 + && rect.top == 0 + && rect.left == 0 + && rect.right == 0)) { - change_frame_size (f, text_width, text_height, 0, 1, 0, 1); - SET_FRAME_GARBAGED (f); - cancel_mouse_face (f); - /* Do we want to set these here ???? */ -/** FRAME_PIXEL_WIDTH (f) = width; **/ -/** FRAME_TEXT_WIDTH (f) = text_width; **/ -/** FRAME_PIXEL_HEIGHT (f) = height; **/ - f->win_gravity = NorthWestGravity; + height = rect.bottom - rect.top; + width = rect.right - rect.left; + text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, width); + text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, height); + rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height); + columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width); + + /* TODO: Clip size to the screen dimensions. */ + + /* Even if the number of character rows and columns + has not changed, the font size may have changed, + so we need to check the pixel dimensions as well. */ + + if (width != FRAME_PIXEL_WIDTH (f) + || height != FRAME_PIXEL_HEIGHT (f) + || text_width != FRAME_TEXT_WIDTH (f) + || text_height != FRAME_TEXT_HEIGHT (f)) + { + change_frame_size (f, text_width, text_height, 0, 1, 0, 1); + SET_FRAME_GARBAGED (f); + cancel_mouse_face (f); + /* Do we want to set these here ???? */ + /** FRAME_PIXEL_WIDTH (f) = width; **/ + /** FRAME_TEXT_WIDTH (f) = text_width; **/ + /** FRAME_PIXEL_HEIGHT (f) = height; **/ + f->win_gravity = NorthWestGravity; + } } } -- 2.39.2