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/attacher.c | 2 +- src/fileio.c | 8 ++++---- src/misc.c | 4 ++-- src/process.c | 16 ++++++++-------- src/resize.c | 6 +++--- src/screen.c | 6 +++--- src/socket.c | 2 +- src/termcap.c | 8 ++++---- src/window.c | 6 +++--- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/attacher.c b/src/attacher.c index 88da744..370d594 100644 --- a/src/attacher.c +++ b/src/attacher.c @@ -756,7 +756,7 @@ LockTerminal() debug2("Lock: %s: return code %d\n", prg, WEXITSTATUS(wstat)); } else - printf(LockEnd); + printf("%s", LockEnd); } } else diff --git a/src/fileio.c b/src/fileio.c index b889df6..88fbf64 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -75,7 +75,7 @@ register char *str1, *str2; { len2 = strlen(str2); if ((cp = realloc(str2, (unsigned) len1 + len2 + add_colon + 1)) == NULL) - Panic(0, strnomem); + Panic(0, "%s", strnomem); bcopy(cp, cp + len1 + add_colon, len2 + 1); } else @@ -83,8 +83,8 @@ register char *str1, *str2; if (len1 == 0) return 0; if ((cp = malloc((unsigned) len1 + add_colon + 1)) == NULL) - Panic(0, strnomem); - cp[len1 + add_colon] = '\0'; + Panic(0, "%s", strnomem); + cp[len1 + add_colon] = '\0'; } bcopy(str1, cp, len1); if (add_colon) @@ -627,7 +627,7 @@ int *lenp; if ((buf = malloc(size)) == NULL) { close(i); - Msg(0, strnomem); + Msg(0, "%s", strnomem); return NULL; } errno = 0; diff --git a/src/misc.c b/src/misc.c index 7bc06f6..ff3bebb 100644 --- a/src/misc.c +++ b/src/misc.c @@ -57,7 +57,7 @@ register const char *str; register char *cp; if ((cp = malloc(strlen(str) + 1)) == NULL) - Panic(0, strnomem); + Panic(0, "%s", strnomem); else strcpy(cp, str); return cp; @@ -71,7 +71,7 @@ int n; register char *cp; if ((cp = malloc(n + 1)) == NULL) - Panic(0, strnomem); + Panic(0, "%s", strnomem); else { bcopy((char *)str, cp, n); diff --git a/src/process.c b/src/process.c index 137037d..d685501 100644 --- a/src/process.c +++ b/src/process.c @@ -691,7 +691,7 @@ int create; kp = malloc(sizeof(*kp)); if (kp == 0) { - Msg(0, strnomem); + Msg(0, "%s", strnomem); return 0; } kp->name = SaveStr(class); @@ -2380,7 +2380,7 @@ int key; */ if ((dbuf = (char *)malloc(l)) == 0) { - Msg(0, strnomem); + Msg(0, "%s", strnomem); break; } l = 0; @@ -2467,7 +2467,7 @@ int key; newbuf = malloc(l + 1); if (!newbuf) { - Msg(0, strnomem); + Msg(0, "%s", strnomem); break; } user->u_plop.len = RecodeBuf((unsigned char *)oldplop.buf, oldplop.len, oldplop.enc, enc, (unsigned char *)newbuf); @@ -4501,9 +4501,9 @@ int *argl; return; } if ((pp = (char **)malloc((unsigned)(argc + 1) * sizeof(char **))) == 0) - Panic(0, strnomem); + Panic(0, "%s", strnomem); if ((lp = (int *)malloc((unsigned)(argc) * sizeof(int *))) == 0) - Panic(0, strnomem); + Panic(0, "%s", strnomem); act->nr = nr; act->args = pp; act->argl = lp; @@ -4525,7 +4525,7 @@ char **args; while (args[argc]) argc++; if ((pp = ap = (char **)malloc((unsigned)(argc + 1) * sizeof(char **))) == 0) - Panic(0, strnomem); + Panic(0, "%s", strnomem); while (argc--) *pp++ = SaveStr(*args++); *pp = 0; @@ -6074,7 +6074,7 @@ char *data; /* dummy */ { if ((pp->buf = (char *)malloc(D_user->u_plop.len)) == NULL) { - Msg(0, strnomem); + Msg(0, "%s", strnomem); return; } bcopy(D_user->u_plop.buf, pp->buf, D_user->u_plop.len); @@ -6281,7 +6281,7 @@ char *data; #endif if (!(u->u_plop.buf = SaveStr(u->u_password))) { - Msg(0, strnomem); + Msg(0, "%s", strnomem); D_user->u_plop.len = 0; } else 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++) diff --git a/src/screen.c b/src/screen.c index 06441dd..e26e4b8 100644 --- a/src/screen.c +++ b/src/screen.c @@ -2052,7 +2052,7 @@ MakeNewEnv() free((char *)NewEnv); NewEnv = np = (char **) malloc((unsigned) (op - environ + 7 + 1) * sizeof(char **)); if (!NewEnv) - Panic(0, strnomem); + Panic(0, "%s", strnomem); sprintf(stybuf, "STY=%s", strlen(SockName) <= MAXSTR - 5 ? SockName : "?"); *np++ = stybuf; /* NewEnv[0] */ *np++ = Term; /* NewEnv[1] */ @@ -2389,7 +2389,7 @@ char **cmdv; bt = (struct backtick *)malloc(sizeof *bt); if (!bt) { - Msg(0, strnomem); + Msg(0, "%s", strnomem); return; } bzero(bt, sizeof(*bt)); @@ -2411,7 +2411,7 @@ char **cmdv; bt->buf = (char *)malloc(MAXSTR); if (bt->buf == 0) { - Msg(0, strnomem); + Msg(0, "%s", strnomem); setbacktick(num, 0, 0, (char **)0); return; } diff --git a/src/socket.c b/src/socket.c index 9e61816..9dbf461 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1540,7 +1540,7 @@ struct msg *m; ASSERT(display); pwdata = (struct pwdata *)malloc(sizeof(struct pwdata)); if (!pwdata) - Panic(0, strnomem); + Panic(0, "%s", strnomem); pwdata->l = 0; pwdata->m = *m; D_processinputdata = (char *)pwdata; diff --git a/src/termcap.c b/src/termcap.c index 8f6b8b9..32ae63d 100644 --- a/src/termcap.c +++ b/src/termcap.c @@ -137,7 +137,7 @@ int he; if ((D_tentry = (char *)malloc(TERMCAP_BUFSIZE + (extra_incap ? strlen(extra_incap) + 1 : 0))) == 0) { - Msg(0, strnomem); + Msg(0, "%s", strnomem); return -1; } @@ -1198,7 +1198,7 @@ char *s; if ((D_xtable = (char ***)calloc(256, sizeof(char **))) == 0) { - Msg(0, strnomem); + Msg(0, "%s", strnomem); return -1; } @@ -1216,7 +1216,7 @@ char *s; { if ((D_xtable[curchar] = (char **)calloc(257, sizeof(char *))) == 0) { - Msg(0, strnomem); + Msg(0, "%s", strnomem); FreeTransTable(); return -1; } @@ -1250,7 +1250,7 @@ char *s; l = l * templnsub + templlen; if ((ctable[c] = (char *)malloc(l + 1)) == 0) { - Msg(0, strnomem); + Msg(0, "%s", strnomem); FreeTransTable(); return -1; } diff --git a/src/window.c b/src/window.c index 99e0bc7..a800d4a 100644 --- a/src/window.c +++ b/src/window.c @@ -613,7 +613,7 @@ struct NewWindow *newwin; if ((p = (struct win *)calloc(1, sizeof(struct win))) == 0) { close(f); - Msg(0, strnomem); + Msg(0, "%s", strnomem); return -1; } @@ -649,7 +649,7 @@ struct NewWindow *newwin; { free((char *)p); close(f); - Msg(0, strnomem); + Msg(0, "%s", strnomem); return -1; } #endif @@ -1530,7 +1530,7 @@ char **av; } if (!(pwin = (struct pseudowin *)calloc(1, sizeof(struct pseudowin)))) { - Msg(0, strnomem); + Msg(0, "%s", strnomem); return -1; } -- cgit v1.2.1 From 7851249fa3e5a9ce00ad3bf8bd0b417acb335f84 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Sun, 7 Mar 2010 19:36:36 -0500 Subject: Changelog. --- src/ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ChangeLog b/src/ChangeLog index c02d5cc..44ba74c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -108,6 +108,7 @@ Version 4.1.0 (??/??/20??): * Ryan Niebur * Jan Christoph Nordholz * William Pursell + * Michael Scherer * Enrico Scholz * Peter Teichman -- cgit v1.2.1 From eb4cea75f23df90ac955e001fc5c3e54062d97cb Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Mon, 8 Mar 2010 10:01:26 -0500 Subject: Fix refresh when double-cell characters end a line Double cell characters that end a line are not properly displayed when there are split regions. Takeshi Banse detected the problem and a fix for it in Savannag bug #29106. A better fix for this was applied in the unicode++ branch, but that won't work in 'master'. This is approximately the same fix, in a slightly different way. --- src/ChangeLog | 1 + src/layer.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/ChangeLog b/src/ChangeLog index 44ba74c..0ac432a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -91,6 +91,7 @@ Version 4.1.0 (??/??/20??): * Dick * Gabriel * Benjamin Andresen + * Takeshi Banse * Maarten Billemont * Curtis Brown * Cyril Brulebois diff --git a/src/layer.c b/src/layer.c index 34cd6a3..b7cea6a 100644 --- a/src/layer.c +++ b/src/layer.c @@ -1197,6 +1197,7 @@ int pause; struct canvas *cv; struct display *olddisplay = display; int line; + struct win *win; pause = !!pause; @@ -1215,6 +1216,11 @@ int pause; layer->l_pause.bottom == -1) return; + if (layer->l_layfn == &WinLf) /* Currently, this will always be the case! */ + win = layer->l_data; + else + win = NULL; + for (cv = layer->l_cvlist; cv; cv = cv->c_lnext) { struct viewport *vp; @@ -1240,6 +1246,15 @@ int pause; if (xs < vp->v_xs) xs = vp->v_xs; if (xe > vp->v_xe) xe = vp->v_xe; +#if defined(DW_CHARS) && defined(UTF8) + if (layer->l_encoding == UTF8 && xe < vp->v_xe && win) + { + struct mline *ml = win->w_mlines + line; + if (dw_left(ml, xe, UTF8)) + xe++; + } +#endif + if (xs <= xe) RefreshLine(line + vp->v_yoff, xs, xe, 0); } -- cgit v1.2.1 From 25ff9f7a8bf4e7e90ed6e2c26d8e3a32fd5a9368 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Mon, 8 Mar 2010 14:29:40 -0500 Subject: Fix a hardstatus update issue. The initial change was to fix a bug in gnome-terminal (https://savannah.gnu.org/bugs/?23699), but that broke hardstatus update issues on bell (https://savannah.gnu.org/bugs/?24096). So apply a proper fix for #23699 without causing #24096. --- src/display.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/display.c b/src/display.c index 36368aa..5fc5f4b 100644 --- a/src/display.c +++ b/src/display.c @@ -2327,26 +2327,7 @@ int y, from, to, isblank; return; /* can't refresh status */ } - /* The following check makes plenty of sense. Unfortunately, - vte-based terminals (notably gnome-terminal) experience a quirk - that causes the final line not to update properly when it falls outside - the scroll region; clearing the line with D_CE avoids the glitch, - so we'll disable this perfectly sensible shortcut until such a time - as widespread vte installations lack the glitch. - - See http://bugzilla.gnome.org/show_bug.cgi?id=542087 for current - status of the VTE bug report, and - https://savannah.gnu.org/bugs/index.php?23699 for the history from - the Savannah BTS. */ -#if 0 - if (y == D_height - 1 && D_has_hstatus == HSTATUS_LASTLINE) - { - RefreshHStatus(); - return; - } -#endif - - if (isblank == 0 && D_CE && to == D_width - 1 && from < to) + if (isblank == 0 && D_CE && to == D_width - 1 && from < to && D_status != STATUS_ON_HS) { GotoPos(from, y); if (D_UT || D_BE) @@ -2354,6 +2335,13 @@ int y, from, to, isblank; AddCStr(D_CE); isblank = 1; } + + if (y == D_height - 1 && D_has_hstatus == HSTATUS_LASTLINE) + { + RefreshHStatus(); + return; + } + while (from <= to) { lcv = 0; -- cgit v1.2.1 From 26c3a1a371aaa55e2ee322d8c722e1f46bed5d38 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Mon, 8 Mar 2010 15:04:22 -0500 Subject: More fixes for -Werror=format-security. --- src/screen.c | 2 +- src/utmp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/screen.c b/src/screen.c index e26e4b8..65c51bb 100644 --- a/src/screen.c +++ b/src/screen.c @@ -818,7 +818,7 @@ char **av; size_t newsz; char *newbuf = malloc(3 * len); if (!newbuf) - Panic(0, strnomem); + Panic(0, "%s", strnomem); newsz = RecodeBuf(nwin_options.aka, len, nwin_options.encoding, 0, newbuf); newbuf[newsz] = '\0'; diff --git a/src/utmp.c b/src/utmp.c index 20f3c3c..afa0948 100644 --- a/src/utmp.c +++ b/src/utmp.c @@ -268,7 +268,7 @@ InitUtmp() if ((utmpfd = open(UtmpName, O_RDWR)) == -1) { if (errno != EACCES) - Msg(errno, UtmpName); + Msg(errno, "%s", UtmpName); debug("InitUtmp failed.\n"); utmpok = 0; return; -- cgit v1.2.1 From 2d92e194efbb7973847640a4fb78b4be30603700 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Tue, 9 Mar 2010 16:34:06 -0500 Subject: Fix an invalid memory read. The window-list data gets freed when we abort the list. So read what we need to before aborting the list. --- src/list_window.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/list_window.c b/src/list_window.c index c46aa9e..ee71fde 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -413,10 +413,10 @@ gl_Window_input(struct ListData *ldata, char **inp, int *len) case 007: /* ^G */ if (!WLIST_FOR_GROUP(wdata)) { - int fnumber = wdata->fore->w_number; + int fnumber = wdata->onblank ? wdata->fore->w_number : -1; glist_abort(); display = cd; - if (wdata->onblank) + if (fnumber >= 0) SwitchWindow(fnumber); *len = 0; } -- cgit v1.2.1 From 9d3938870c639fad97ea9b6cbb23b46cb049c801 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Tue, 9 Mar 2010 17:05:57 -0500 Subject: Fix compiling SIMPLESCREEN. --- src/screen.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/screen.c b/src/screen.c index 65c51bb..2a905a8 100644 --- a/src/screen.c +++ b/src/screen.c @@ -2847,6 +2847,7 @@ int rec; break; case 'P': p--; +#ifdef COPY_PASTE if (display && ev && ev != &D_hstatusev) /* Hack */ { /* Is the layer in the current canvas in copy mode? */ @@ -2854,6 +2855,7 @@ int rec; if (ev == &cv->c_captev && cv->c_layer->l_layfn == &MarkLf) qmflag = 1; } +#endif break; case '>': truncpos = p - winmsg_buf; -- 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/list_generic.c | 27 +++++++++++++++----- src/resize.c | 73 ++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 67 insertions(+), 33 deletions(-) diff --git a/src/list_generic.c b/src/list_generic.c index 2b3be4c..e32acf7 100644 --- a/src/list_generic.c +++ b/src/list_generic.c @@ -344,18 +344,33 @@ static void ListFree(void *d) static void ListRedisplayLine(int y, int xs, int xe, int isblank) { + struct ListData *ldata; ASSERT(flayer); + + ldata = flayer->l_data; if (y < 0) { - glist_display_all(flayer->l_data); + glist_display_all(ldata); return; } - if (y != 0 && y != flayer->l_height - 1) - return; - if (isblank) - return; - LClearArea(flayer, xs, y, xe, y, 0, 0); + if (!isblank) + LClearArea(flayer, xs, y, xe, y, 0, 0); + + if (ldata->top && y < ldata->top->y) + ldata->list_fn->gl_printheader(ldata); + else if (y + 1 == flayer->l_height) + ldata->list_fn->gl_printfooter(ldata); + else + { + struct ListRow *row; + for (row = ldata->top; row && row->y != -1; row = row->next) + if (row->y == y) + { + ldata->list_fn->gl_printrow(ldata, row); + break; + } + } } static void ListClearLine(int y, int xs, int xe, int bce) 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