1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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 {
|