From f04882c76d0d23a35942e736e89ef19268f541b5 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Sat, 7 Feb 2009 20:00:26 -0500 Subject: Copyright for 2009 --- src/resize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/resize.c') diff --git a/src/resize.c b/src/resize.c index a9a8772..0bf5f3d 100644 --- a/src/resize.c +++ b/src/resize.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2008 +/* Copyright (c) 2008, 2009 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de) * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de) * Micah Cowan (micah@cowan.name) -- cgit v1.2.1 From 45d0c395945d2ae0f99748d030a8bffcb4cb46f9 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Wed, 23 Sep 2009 16:22:06 -0400 Subject: Fix a crash when resizing. The alternate screen has to be reset after a resize. Thanks to Enrico Scholz for pointing this out. Closes savannah bug #26742. --- src/resize.c | 60 +++++++++++++++++++++++------------------------------------- 1 file changed, 23 insertions(+), 37 deletions(-) (limited to 'src/resize.c') diff --git a/src/resize.c b/src/resize.c index 0bf5f3d..5477bb7 100644 --- a/src/resize.c +++ b/src/resize.c @@ -497,6 +497,7 @@ CheckMaxSize(wi) int wi; { unsigned char *oldnull = null; + unsigned char *oldblank = blank; struct win *p; int i; struct mline *ml; @@ -542,49 +543,34 @@ int wi; # endif #endif +#define RESET_AFC(x, bl) do { if (x == old##bl) x = bl; } while (0) + +#define RESET_LINES(lines, count) \ + do { \ + ml = lines; \ + for (i = 0; i < count; i++, ml++) \ + { \ + RESET_AFC(ml->image, blank); \ + RESET_AFC(ml->attr, null); \ + IFFONT(RESET_AFC(ml->font, null)); \ + IFCOLOR(RESET_AFC(ml->color, null)); \ + IFCOLORX(RESET_AFC(ml->colorx, null)); \ + } \ + } while (0) + /* We have to run through all windows to substitute - * the null references. + * the null and blank references. */ for (p = windows; p; p = p->w_next) { - ml = p->w_mlines; - for (i = 0; i < p->w_height; i++, ml++) - { - if (ml->attr == oldnull) - ml->attr = null; -#ifdef FONT - if (ml->font == oldnull) - ml->font = null; -#endif -#ifdef COLOR - if (ml->color == oldnull) - ml->color= null; -#ifdef COLORS256 - if (ml->colorx == oldnull) - ml->colorx = null; -#endif -#endif - } + RESET_LINES(p->w_mlines, p->w_height); + #ifdef COPY_PASTE - ml = p->w_hlines; - for (i = 0; i < p->w_histheight; i++, ml++) - { - if (ml->attr == oldnull) - ml->attr = null; -# ifdef FONT - if (ml->font == oldnull) - ml->font = null; -# endif -# ifdef COLOR - if (ml->color == oldnull) - ml->color= null; -# ifdef COLORS256 - if (ml->colorx == oldnull) - ml->colorx = null; -# endif -# endif - } + RESET_LINES(p->w_hlines, p->w_histheight); + RESET_LINES(p->w_alt_hlines, p->w_alt_histheight); #endif + + RESET_LINES(p->w_alt_mlines, p->w_alt_height); } } -- cgit v1.2.1 From 7cb17d54cc8fca88e17d6d1e7be2fd49daef1b9d Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Wed, 23 Sep 2009 16:24:21 -0400 Subject: Typo fix. Fixing this typo fixes this crash: https://bugzilla.redhat.com/show_bug.cgi?id=515055 --- src/resize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/resize.c') diff --git a/src/resize.c b/src/resize.c index 5477bb7..9c7b70f 100644 --- a/src/resize.c +++ b/src/resize.c @@ -517,7 +517,7 @@ int wi; #ifdef COLOR mline_old.color = (unsigned char *)xrealloc((char *)mline_old.color, maxwidth); # ifdef COLORS256 - mline_old.colorx = (unsigned char *)xrealloc((char *)mline_old.color, maxwidth); + mline_old.colorx = (unsigned char *)xrealloc((char *)mline_old.colorx, maxwidth); # endif #endif if (!(blank && null && mline_old.image && mline_old.attr IFFONT(&& mline_old.font) IFCOLOR(&& mline_old.color) IFCOLORX(&& mline_old.colorx))) -- cgit v1.2.1 From ad56f746c6243d45124485d198d577bdbb78071c Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Sun, 29 Nov 2009 23:34:25 -0500 Subject: Fix using alternate screen buffers in some cases. Screen would reset the 'main' screen buffer if an app tries to switch to an alternate buffer while it is already using one (in other words, sends multiple 'smcup' without an 'rmcup'). This should fix debian bug #558724. --- src/resize.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'src/resize.c') diff --git a/src/resize.c b/src/resize.c index 9c7b70f..1afdf5a 100644 --- a/src/resize.c +++ b/src/resize.c @@ -1026,16 +1026,20 @@ struct win *p; struct mline *ml; int t; - ml = p->w_alt_mlines; p->w_alt_mlines = p->w_mlines; p->w_mlines = ml; - t = p->w_alt_width; p->w_alt_width = p->w_width; p->w_width = t; - t = p->w_alt_height; p->w_alt_height = p->w_height; p->w_height = t; - t = p->w_alt_histheight; p->w_alt_histheight = p->w_histheight; p->w_histheight = t; - t = p->w_alt_x; p->w_alt_x = p->w_x; p->w_x = t; - t = p->w_alt_y; p->w_alt_y = p->w_y; p->w_y = t; +#define SWAP(item, t) do { (t) = p->w_alt_##item; p->w_alt_##item = p->w_##item; p->w_##item = (t); } while (0) + + SWAP(mlines, ml); + SWAP(width, t); + SWAP(height, t); + SWAP(histheight, t); + SWAP(x, t); + SWAP(y, t); + #ifdef COPY_PASTE - ml = p->w_alt_hlines; p->w_alt_hlines = p->w_hlines; p->w_hlines = ml; - t = p->w_alt_histidx; p->w_alt_histidx = p->w_histidx; p->w_histidx = t; + SWAP(hlines, ml); + SWAP(histidx, t); #endif +#undef SWAP } void @@ -1043,20 +1047,34 @@ EnterAltScreen(p) struct win *p; { int ox = p->w_x, oy = p->w_y; - FreeAltScreen(p); - SwapAltScreen(p); + if (!p->w_alt_current) + { + /* If not already using the alternate screen buffer, then create + a new one and swap it with the 'real' screen buffer. */ + FreeAltScreen(p); + SwapAltScreen(p); + } + else + { + /* Already using the alternate buffer. Just clear the screen. To do so, it + is only necessary to reset the height(s) without resetting the width. */ + p->w_height = 0; + p->w_histheight = 0; + } ChangeWindowSize(p, p->w_alt_width, p->w_alt_height, p->w_alt_histheight); p->w_x = ox; p->w_y = oy; + p->w_alt_current = 1; } void LeaveAltScreen(p) struct win *p; { - if (!p->w_alt_mlines) + if (!p->w_alt_current) return; SwapAltScreen(p); ChangeWindowSize(p, p->w_alt_width, p->w_alt_height, p->w_alt_histheight); FreeAltScreen(p); + p->w_alt_current = 0; } -- cgit v1.2.1 From 7ac593d74dfd2243cd60c5d848547ebd9971a8b0 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Sat, 19 Dec 2009 18:44:45 -0500 Subject: Cap the maximum sizes of a window. --- src/resize.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/resize.c') diff --git a/src/resize.c b/src/resize.c index 1afdf5a..553b0ed 100644 --- a/src/resize.c +++ b/src/resize.c @@ -633,6 +633,27 @@ int wi, he, hi; if (p->w_type == W_TYPE_GROUP) return 0; + + if (wi > 1000) + { + Msg(0, "Window width too large. Truncated to 1000."); + wi = 1000; + } + + if (he > 1000) + { + Msg(0, "Window height too large. Truncated to 1000."); + he = 1000; + } + +#ifdef COPY_PASTE + if (hi > 1000) + { + Msg(0, "Window history too big. Truncated to 1000."); + hi = 1000; + } +#endif + if (p->w_width == wi && p->w_height == he && p->w_histheight == hi) { debug("ChangeWindowSize: No change.\n"); -- cgit v1.2.1 From b9253ef24e70f7a7bbfe320b1c3639da52d740f0 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Wed, 3 Mar 2010 11:55:39 -0500 Subject: Do not terminate when size is reduced too much. Height of a window can be negative, when both hardstatus and caption are turned on, and the terminal size is reduced to one-line height. So handle those cases more gracefully. Fixes savannah bug #29037. --- src/resize.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/resize.c') diff --git a/src/resize.c b/src/resize.c index 553b0ed..39f6e28 100644 --- a/src/resize.c +++ b/src/resize.c @@ -628,8 +628,8 @@ int wi, he, hi; int ncx, ncy, naka, t; int y, shift; - if (wi == 0) - he = hi = 0; + if (wi <= 0 || he <= 0) + wi = he = hi = 0; if (p->w_type == W_TYPE_GROUP) return 0; -- cgit v1.2.1 From 261a022ce947d17471b73a71345c265df9bfe7a4 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sun, 7 Mar 2010 19:29:39 -0500 Subject: Fix build with -Werror=format-security Some distributions ( mandriva for example ) use -Werror=format-security by default when build C software to try to enhance code quality and prevent security bugs. As the policy is to correct all occurences of the error ( so there is no false positive, nor question about to fix it or not ), a patch that fix the error on gnu screen 4.0.3 have been added to the package. I have rediffed it against latest git snapshot, to be sent upstream. It mainly add "%s" where applicable. --- src/resize.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/resize.c') diff --git a/src/resize.c b/src/resize.c index 39f6e28..10dfd8e 100644 --- a/src/resize.c +++ b/src/resize.c @@ -521,7 +521,7 @@ int wi; # endif #endif if (!(blank && null && mline_old.image && mline_old.attr IFFONT(&& mline_old.font) IFCOLOR(&& mline_old.color) IFCOLORX(&& mline_old.colorx))) - Panic(0, strnomem); + Panic(0, "%s", strnomem); MakeBlankLine(blank, maxwidth); bzero((char *)null, maxwidth); @@ -691,7 +691,7 @@ int wi, he, hi; if ((nmlines = (struct mline *)calloc(he, sizeof(struct mline))) == 0) { KillWindow(p); - Msg(0, strnomem); + Msg(0, "%s", strnomem); return -1; } } @@ -924,7 +924,7 @@ int wi, he, hi; #endif } KillWindow(p); - Msg(0, strnomem); + Msg(0, "%s", strnomem); return -1; } for (; t < wi; t++) -- cgit v1.2.1 From cd874b642ce9f86d63583b6a2d012d5f445895da Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Wed, 10 Mar 2010 00:49:44 -0500 Subject: Make layer-resizing a bit more robust and readable Instead of killing all overlays when resizing, just kill the ones that cannot be resized, and the resized the rest. This fixes a bug where the window-list (or a group-window) is aborted when layer-size changes (because window-size changed, or caption/hardstatus etc. was toggled). This also makes the code robust. So if you are looking at a window/display list, and the window-size is changed, the list won't go away. --- src/resize.c | 73 ++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 27 deletions(-) (limited to 'src/resize.c') diff --git a/src/resize.c b/src/resize.c index 10dfd8e..7782c2b 100644 --- a/src/resize.c +++ b/src/resize.c @@ -323,6 +323,34 @@ kaablamm() Msg(0, "Aborted because of window size change."); } +/* Kills non-resizable layers. */ +#define RESIZE_OR_KILL_LAYERS(l, wi, he) do \ + { \ + struct layer *_last = NULL, *_iter; \ + flayer = (l); \ + while (flayer->l_next) \ + { \ + if (LayResize(wi, he) == 0) \ + { \ + _last = flayer; \ + flayer = flayer->l_next; \ + } \ + else \ + { \ + struct canvas *_cv; \ + for (_cv = flayer->l_cvlist; _cv; _cv = _cv->c_lnext) \ + _cv->c_display->d_kaablamm = 1; \ + ExitOverlayPage(); \ + if (_last) \ + _last->l_next = flayer; \ + } \ + } \ + /* We assume that the bottom-most layer, i.e. when flayer->l_next == 0, \ + * is always resizable. Currently, WinLf and BlankLf can be the bottom-most layers. \ + */ \ + LayResize(wi, he); \ + } while (0) + void ResizeLayer(l, wi, he, norefdisp) struct layer *l; @@ -338,52 +366,40 @@ struct display *norefdisp; return; p = Layer2Window(l); + /* If 'flayer' and 'l' are for the same window, then we will not + * restore 'flayer'. */ if (oldflayer && (l == oldflayer || Layer2Window(oldflayer) == p)) while (oldflayer->l_next) oldflayer = oldflayer->l_next; - + + flayer = l; + if (p) { + /* It's a window layer. Kill the overlays on it in all displays. */ for (d = displays; d; d = d->d_next) for (cv = d->d_cvlist; cv; cv = cv->c_next) { if (p == Layer2Window(cv->c_layer)) { - flayer = cv->c_layer; - if (flayer->l_next) - d->d_kaablamm = 1; - while (flayer->l_next) - ExitOverlayPage(); + /* Canvas 'cv' on display 'd' shows this window. Remove any non-resizable + * layers over it. */ + RESIZE_OR_KILL_LAYERS(cv->c_layer, wi, he); } } - l = p->w_savelayer; - } - flayer = l; - if (p == 0 && flayer->l_next && flayer->l_next->l_next == 0 && LayResize(wi, he) == 0) - { - flayer = flayer->l_next; - LayResize(wi, he); - flayer = l; } else { - if (flayer->l_next) - for (cv = flayer->l_cvlist; cv; cv = cv->c_lnext) - cv->c_display->d_kaablamm = 1; - while (flayer->l_next) - ExitOverlayPage(); + /* It's a Blank layer. Just kill the non-resizable overlays over it. */ + RESIZE_OR_KILL_LAYERS(flayer, wi, he); } - if (p) - flayer = &p->w_layer; - LayResize(wi, he); - /* now everybody is on flayer, redisplay */ - l = flayer; + for (display = displays; display; display = display->d_next) { if (display == norefdisp) continue; for (cv = D_cvlist; cv; cv = cv->c_next) - if (cv->c_layer == l) + if (Layer2Window(cv->c_layer) == p) { CV_CALL(cv, LayRedisplayLine(-1, -1, -1, 0)); RefreshArea(cv->c_xs, cv->c_ys, cv->c_xe, cv->c_ye, 0); @@ -394,11 +410,14 @@ struct display *norefdisp; D_kaablamm = 0; } } - flayer = oldflayer; + + /* If we started resizing a non-flayer layer, then restore the flayer. + * Otherwise, flayer should already be updated to the topmost foreground layer. */ + if (Layer2Window(flayer) != Layer2Window(oldflayer)) + flayer = oldflayer; display = olddisplay; } - static void FreeMline(ml) struct mline *ml; -- cgit v1.2.1 From 08939ef8428d4cde3c76adef1ec8ef253c3f669c Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Fri, 12 Mar 2010 19:25:50 -0500 Subject: Fix an invalid memory read. Thanks a bunch to Friedrich Delgado Friedrichs for providing the valgrind logs. --- src/resize.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/resize.c') diff --git a/src/resize.c b/src/resize.c index 7782c2b..5d1df4b 100644 --- a/src/resize.c +++ b/src/resize.c @@ -369,8 +369,7 @@ struct display *norefdisp; /* If 'flayer' and 'l' are for the same window, then we will not * restore 'flayer'. */ if (oldflayer && (l == oldflayer || Layer2Window(oldflayer) == p)) - while (oldflayer->l_next) - oldflayer = oldflayer->l_next; + oldflayer = NULL; flayer = l; @@ -413,7 +412,7 @@ struct display *norefdisp; /* If we started resizing a non-flayer layer, then restore the flayer. * Otherwise, flayer should already be updated to the topmost foreground layer. */ - if (Layer2Window(flayer) != Layer2Window(oldflayer)) + if (oldflayer) flayer = oldflayer; display = olddisplay; } -- cgit v1.2.1