diff options
Diffstat (limited to 'patches/procps-3.2.7/generic/20_top_c_resize.dpatch')
-rw-r--r-- | patches/procps-3.2.7/generic/20_top_c_resize.dpatch | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/patches/procps-3.2.7/generic/20_top_c_resize.dpatch b/patches/procps-3.2.7/generic/20_top_c_resize.dpatch new file mode 100644 index 000000000..4cc9c6c51 --- /dev/null +++ b/patches/procps-3.2.7/generic/20_top_c_resize.dpatch @@ -0,0 +1,75 @@ +#! /bin/sh /usr/share/dpatch/dpatch-run +## 20top_resize_terminal.dpatch by <hesso@pool.math.tu-berlin.de> +## +## DP: Prevent top from segfaulting when the display is shrinked to only +## DP: a few (read: 3 or less) lines. + +@DPATCH@ +--- procps-3.2.7.orig/top.c 2006-06-25 08:41:48.000000000 +0200 ++++ procps-3.2.7/top.c 2007-08-06 03:27:28.000000000 +0200 +@@ -140,7 +140,7 @@ + are exploited in a macro and represent 90% of our optimization. + The Stdout_buf is transparent to our code and regardless of whose + buffer is used, stdout is flushed at frame end or if interactive. */ +-static char *Pseudo_scrn; ++static PSEUDO_SCREEN_t Pseudo_scrn; + static int Pseudo_row, Pseudo_cols, Pseudo_size; + #ifndef STDOUT_IOLBF + // less than stdout's normal buffer but with luck mostly '\n' anyway +@@ -2415,7 +2415,10 @@ + Pseudo_cols = Screen_cols + CLRBUFSIZ + 1; + if (Batch) Pseudo_size = ROWBUFSIZ + 1; + else Pseudo_size = Pseudo_cols * Screen_rows; +- Pseudo_scrn = alloc_r(Pseudo_scrn, Pseudo_size); ++ if( Pseudo_scrn.buf == NULL || Pseudo_size > Pseudo_scrn.mem_size ) { ++ Pseudo_scrn.buf = alloc_r(Pseudo_scrn.buf, Pseudo_size); ++ Pseudo_scrn.mem_size = Pseudo_size; ++ } + + // force rebuild of column headers AND libproc/readproc requirements + Frames_libflags = 0; +@@ -3289,7 +3292,7 @@ + // reframewins(), who also builds each window's column headers + if (!Frames_libflags) { + reframewins(); +- memset(Pseudo_scrn, '\0', Pseudo_size); ++ memset(Pseudo_scrn.buf, '\0', Pseudo_size); + } + Pseudo_row = Msg_row = scrlins = 0; + ppt = summary_show(); +--- procps-3.2.7.orig/top.h 2006-06-25 08:41:48.000000000 +0200 ++++ procps-3.2.7/top.h 2007-08-06 03:27:28.000000000 +0200 +@@ -135,7 +135,7 @@ + int _len = 1 + snprintf(_str, sizeof(_str), fmt, ## arg); \ + putp ( Batch ? _str : \ + ({ \ +- char *restrict const _pse = &Pseudo_scrn[Pseudo_row++ * Pseudo_cols]; \ ++ char *restrict const _pse = &Pseudo_scrn.buf[Pseudo_row++ * Pseudo_cols]; \ + memcmp(_pse, _str, _len) ? memcpy(_pse, _str, _len) : "\n"; \ + }) \ + ); \ +@@ -149,7 +149,11 @@ + int _len = 1 + snprintf(_str, sizeof(_str), fmt, ## arg); \ + if (Batch) _ptr = _str; \ + else { \ +- _ptr = &Pseudo_scrn[Pseudo_row++ * Pseudo_cols]; \ ++ if (Pseudo_row * Pseudo_cols + _len > Pseudo_size) { \ ++ Pseudo_scrn.buf = realloc(Pseudo_scrn.buf, Pseudo_row * Pseudo_cols + _len); \ ++ Pseudo_scrn.mem_size = Pseudo_size = Pseudo_row * Pseudo_cols + _len; \ ++ } \ ++ _ptr = &Pseudo_scrn.buf[Pseudo_row++ * Pseudo_cols]; \ + if (memcmp(_ptr, _str, _len)) { \ + memcpy(_ptr, _str, _len); \ + } else { \ +@@ -237,6 +241,11 @@ + RCW_t win [4]; // a 'WIN_t.rc' for each of the 4 windows + } RCF_t; + ++typedef struct PSEUDO_SCREEN_t { ++ char *buf; ++ int mem_size; ++} PSEUDO_SCREEN_t; ++ + // The scaling 'type' used with scale_num() -- this is how + // the passed number is interpreted should scaling be necessary + enum scale_num { |