mirror of
https://github.com/sheumann/hush.git
synced 2024-08-17 00:29:03 +00:00
Memory cleanups and fix for echo "foo" | sed 's/foo/bar/;H;q'
This commit is contained in:
parent
8417c8c38b
commit
294d113adb
@ -865,6 +865,7 @@ static void process_file(FILE * file)
|
|||||||
case 'd':
|
case 'd':
|
||||||
altered++;
|
altered++;
|
||||||
deleted = 1;
|
deleted = 1;
|
||||||
|
force_print = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
@ -1031,16 +1032,29 @@ static void process_file(FILE * file)
|
|||||||
break;
|
break;
|
||||||
case 'g': /* Replace pattern space with hold space */
|
case 'g': /* Replace pattern space with hold space */
|
||||||
free(pattern_space);
|
free(pattern_space);
|
||||||
pattern_space = strdup(hold_space);
|
if (hold_space) {
|
||||||
|
pattern_space = strdup(hold_space);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'G': { /* Append newline and hold space to pattern space */
|
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) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case 'h': /* Replace hold space with pattern space */
|
case 'h': /* Replace hold space with pattern space */
|
||||||
|
Loading…
Reference in New Issue
Block a user