aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/ed.c8
-rw-r--r--editors/sed.c15
2 files changed, 12 insertions, 11 deletions
diff --git a/editors/ed.c b/editors/ed.c
index 731aef1cb..e6576b406 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -9,9 +9,11 @@
9 9
10#include "libbb.h" 10#include "libbb.h"
11 11
12#define searchString bb_common_bufsiz1
13
12enum { 14enum {
13 USERSIZE = sizeof(bb_common_bufsiz1) > 1024 ? 1024 15 USERSIZE = sizeof(searchString) > 1024 ? 1024
14 : sizeof(bb_common_bufsiz1) - 1, /* max line length typed in by user */ 16 : sizeof(searchString) - 1, /* max line length typed in by user */
15 INITBUF_SIZE = 1024, /* initial buffer size */ 17 INITBUF_SIZE = 1024, /* initial buffer size */
16}; 18};
17 19
@@ -22,8 +24,6 @@ typedef struct LINE {
22 char data[1]; 24 char data[1];
23} LINE; 25} LINE;
24 26
25#define searchString bb_common_bufsiz1
26
27static LINE lines, *curLine; 27static LINE lines, *curLine;
28static int curNum, lastNum, marks[26], dirty; 28static int curNum, lastNum, marks[26], dirty;
29static char *bufBase, *bufPtr, *fileName; 29static char *bufBase, *bufPtr, *fileName;
diff --git a/editors/sed.c b/editors/sed.c
index d49627ff4..d0c2ca742 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -118,8 +118,14 @@ struct globals {
118 int len; /* Space allocated */ 118 int len; /* Space allocated */
119 } pipeline; 119 } pipeline;
120}; 120};
121
122#define G (*(struct globals*)&bb_common_bufsiz1) 121#define G (*(struct globals*)&bb_common_bufsiz1)
122void BUG_sed_globals_too_big(void);
123#define INIT_G() do { \
124 if (sizeof(struct globals) > COMMON_BUFSIZE) \
125 BUG_sed_globals_too_big(); \
126 G.sed_cmd_tail = &G.sed_cmd_head; \
127} while (0)
128
123 129
124#if ENABLE_FEATURE_CLEAN_UP 130#if ENABLE_FEATURE_CLEAN_UP
125static void sed_free_and_close_stuff(void) 131static void sed_free_and_close_stuff(void)
@@ -1210,8 +1216,6 @@ static void add_cmd_block(char *cmdstr)
1210 free(sv); 1216 free(sv);
1211} 1217}
1212 1218
1213void BUG_sed_globals_too_big(void);
1214
1215int sed_main(int argc, char **argv); 1219int sed_main(int argc, char **argv);
1216int sed_main(int argc, char **argv) 1220int sed_main(int argc, char **argv)
1217{ 1221{
@@ -1222,10 +1226,7 @@ int sed_main(int argc, char **argv)
1222 llist_t *opt_e, *opt_f; 1226 llist_t *opt_e, *opt_f;
1223 int status = EXIT_SUCCESS; 1227 int status = EXIT_SUCCESS;
1224 1228
1225 if (sizeof(struct globals) > sizeof(bb_common_bufsiz1)) 1229 INIT_G();
1226 BUG_sed_globals_too_big();
1227
1228 G.sed_cmd_tail = &G.sed_cmd_head;
1229 1230
1230 /* destroy command strings on exit */ 1231 /* destroy command strings on exit */
1231 if (ENABLE_FEATURE_CLEAN_UP) atexit(sed_free_and_close_stuff); 1232 if (ENABLE_FEATURE_CLEAN_UP) atexit(sed_free_and_close_stuff);