diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-14 16:28:08 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-14 16:28:08 +0000 |
commit | 294d113adb6ff175ad1729e35888c36b0fc824d1 (patch) | |
tree | 46400d26534053f78b5b19e1a4f47871d01e9e2d | |
parent | 8417c8c38bdcab79989ceab50382eb6314505c93 (diff) | |
download | busybox-w32-294d113adb6ff175ad1729e35888c36b0fc824d1.tar.gz busybox-w32-294d113adb6ff175ad1729e35888c36b0fc824d1.tar.bz2 busybox-w32-294d113adb6ff175ad1729e35888c36b0fc824d1.zip |
Memory cleanups and fix for `echo "foo" | sed 's/foo/bar/;H;q'`
-rw-r--r-- | editors/sed.c | 26 |
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) | |||
865 | case 'd': | 865 | case 'd': |
866 | altered++; | 866 | altered++; |
867 | deleted = 1; | 867 | deleted = 1; |
868 | force_print = 0; | ||
868 | break; | 869 | break; |
869 | 870 | ||
870 | case 's': | 871 | case 's': |
@@ -1031,16 +1032,29 @@ static void process_file(FILE * file) | |||
1031 | break; | 1032 | break; |
1032 | case 'g': /* Replace pattern space with hold space */ | 1033 | case 'g': /* Replace pattern space with hold space */ |
1033 | free(pattern_space); | 1034 | free(pattern_space); |
1034 | pattern_space = strdup(hold_space); | 1035 | if (hold_space) { |
1036 | pattern_space = strdup(hold_space); | ||
1037 | } | ||
1035 | break; | 1038 | break; |
1036 | case 'G': { /* Append newline and hold space to pattern space */ | 1039 | case 'G': { /* Append newline and hold space to pattern space */ |
1037 | int pattern_space_size = 0; | 1040 | int pattern_space_size = 2; |
1041 | int hold_space_size = 0; | ||
1042 | |||
1038 | if (pattern_space) { | 1043 | if (pattern_space) { |
1039 | pattern_space_size = strlen(pattern_space); | 1044 | pattern_space_size += strlen(pattern_space); |
1045 | } | ||
1046 | if (hold_space) { | ||
1047 | hold_space_size = strlen(hold_space); | ||
1048 | } | ||
1049 | pattern_space = xrealloc(pattern_space, pattern_space_size + hold_space_size); | ||
1050 | if (pattern_space_size == 2) { | ||
1051 | strcat(pattern_space, "\n"); | ||
1052 | } else { | ||
1053 | strcpy(pattern_space, "\n"); | ||
1054 | } | ||
1055 | if (hold_space) { | ||
1056 | strcat(pattern_space, hold_space); | ||
1040 | } | 1057 | } |
1041 | pattern_space = xrealloc(pattern_space, pattern_space_size + strlen(hold_space) + 2); | ||
1042 | strcat(pattern_space, "\n"); | ||
1043 | strcat(pattern_space, hold_space); | ||
1044 | break; | 1058 | break; |
1045 | } | 1059 | } |
1046 | case 'h': /* Replace hold space with pattern space */ | 1060 | case 'h': /* Replace hold space with pattern space */ |