aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2018-08-25 15:26:41 +0300
committerEli Zaretskii2018-08-25 15:26:41 +0300
commit9a1329e966ecbd22464f607456153bdd4fa0d5ea (patch)
treebb371434ae2d664e23a5100e60d1ee545e8140c6
parent9a613d3ed0331f9fd2528520a96d977ebba57d7d (diff)
downloademacs-9a1329e966ecbd22464f607456153bdd4fa0d5ea.tar.gz
emacs-9a1329e966ecbd22464f607456153bdd4fa0d5ea.zip
Avoid crashes with very wide TTY frames on MS-Windows
* src/w32console.c <glyph_base>: Reduce the number of elements to 80. <glyphs, glyphs_len>: New static variables. (w32con_clear_end_of_line): If the line is wider than the current size of the "empty row" in 'glyphs', reallocate 'glyphs' to support the full width of the frame. This avoids segfaults when the frame is wider than 256 columns. (Bug#32445)
-rw-r--r--src/w32console.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/w32console.c b/src/w32console.c
index ea30853bade..36a6ced2983 100644
--- a/src/w32console.c
+++ b/src/w32console.c
@@ -140,23 +140,36 @@ w32con_clear_frame (struct frame *f)
140} 140}
141 141
142 142
143static struct glyph glyph_base[256]; 143static struct glyph glyph_base[80];
144static struct glyph *glyphs = glyph_base;
145static size_t glyphs_len = ARRAYELTS (glyph_base);
144static BOOL ceol_initialized = FALSE; 146static BOOL ceol_initialized = FALSE;
145 147
146/* Clear from Cursor to end (what's "standout marker"?). */ 148/* Clear from Cursor to end (what's "standout marker"?). */
147static void 149static void
148w32con_clear_end_of_line (struct frame *f, int end) 150w32con_clear_end_of_line (struct frame *f, int end)
149{ 151{
152 /* Time to reallocate our "empty row"? With today's large screens,
153 it is not unthinkable to see TTY frames well in excess of
154 80-character width. */
155 if (end - cursor_coords.X > glyphs_len)
156 {
157 if (glyphs == glyph_base)
158 glyphs = NULL;
159 glyphs = xrealloc (glyphs, FRAME_COLS (f) * sizeof (struct glyph));
160 glyphs_len = FRAME_COLS (f);
161 ceol_initialized = FALSE;
162 }
150 if (!ceol_initialized) 163 if (!ceol_initialized)
151 { 164 {
152 int i; 165 int i;
153 for (i = 0; i < 256; i++) 166 for (i = 0; i < glyphs_len; i++)
154 { 167 {
155 memcpy (&glyph_base[i], &space_glyph, sizeof (struct glyph)); 168 memcpy (&glyphs[i], &space_glyph, sizeof (struct glyph));
156 } 169 }
157 ceol_initialized = TRUE; 170 ceol_initialized = TRUE;
158 } 171 }
159 w32con_write_glyphs (f, glyph_base, end - cursor_coords.X); /* fencepost ? */ 172 w32con_write_glyphs (f, glyphs, end - cursor_coords.X);
160} 173}
161 174
162/* Insert n lines at vpos. if n is negative delete -n lines. */ 175/* Insert n lines at vpos. if n is negative delete -n lines. */
@@ -772,6 +785,15 @@ initialize_w32_display (struct terminal *term, int *width, int *height)
772 *width = 1 + info.srWindow.Right - info.srWindow.Left; 785 *width = 1 + info.srWindow.Right - info.srWindow.Left;
773 } 786 }
774 787
788 /* Force reinitialization of the "empty row" buffer, in case they
789 dumped from a running session. */
790 if (glyphs != glyph_base)
791 {
792 glyphs = NULL;
793 glyphs_len = 0;
794 ceol_initialized = FALSE;
795 }
796
775 if (os_subtype == OS_NT) 797 if (os_subtype == OS_NT)
776 w32_console_unicode_input = 1; 798 w32_console_unicode_input = 1;
777 else 799 else