aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorGravatar Glenn L McGrath <bug1@ihug.co.nz>2003-09-14 16:28:08 +0000
committerGravatar Glenn L McGrath <bug1@ihug.co.nz>2003-09-14 16:28:08 +0000
commit294d113adb6ff175ad1729e35888c36b0fc824d1 (patch)
tree46400d26534053f78b5b19e1a4f47871d01e9e2d /editors
parent8417c8c38bdcab79989ceab50382eb6314505c93 (diff)
downloadbusybox-294d113adb6ff175ad1729e35888c36b0fc824d1.tar.gz
busybox-294d113adb6ff175ad1729e35888c36b0fc824d1.tar.bz2
Memory cleanups and fix for `echo "foo" | sed 's/foo/bar/;H;q'`
Diffstat (limited to 'editors')
-rw-r--r--editors/sed.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/editors/sed.c b/editors/sed.c
index f0a3c028f..43395b392 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -865,6 +865,7 @@ static void process_file(FILE * file)
case 'd':
altered++;
deleted = 1;
+ force_print = 0;
break;
case 's':
@@ -1031,16 +1032,29 @@ static void process_file(FILE * file)
break;
case 'g': /* Replace pattern space with hold space */
free(pattern_space);
- pattern_space = strdup(hold_space);
+ if (hold_space) {
+ pattern_space = strdup(hold_space);
+ }
break;
case 'G': { /* Append newline and hold space to pattern space */
- int pattern_space_size = 0;
+ int pattern_space_size = 2;
+ int hold_space_size = 0;
+
if (pattern_space) {
- pattern_space_size = strlen(pattern_space);
+ pattern_space_size += strlen(pattern_space);
+ }
+ if (hold_space) {
+ hold_space_size = strlen(hold_space);
+ }
+ pattern_space = xrealloc(pattern_space, pattern_space_size + hold_space_size);
+ if (pattern_space_size == 2) {
+ strcat(pattern_space, "\n");
+ } else {
+ strcpy(pattern_space, "\n");
+ }
+ if (hold_space) {
+ strcat(pattern_space, hold_space);
}
- pattern_space = xrealloc(pattern_space, pattern_space_size + strlen(hold_space) + 2);
- strcat(pattern_space, "\n");
- strcat(pattern_space, hold_space);
break;
}
case 'h': /* Replace hold space with pattern space */