aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-09-15 09:22:04 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-09-15 09:22:04 +0000
commite3e28d3bb64e1b6d2883ee46405d12179b5b8407 (patch)
tree96ddfcd0eee8039dec488c760bbac8a3f0988e65
parent8efe967018dd79aacfe3ca1e2583f115d744e466 (diff)
downloadbusybox-w32-e3e28d3bb64e1b6d2883ee46405d12179b5b8407.tar.gz
busybox-w32-e3e28d3bb64e1b6d2883ee46405d12179b5b8407.tar.bz2
busybox-w32-e3e28d3bb64e1b6d2883ee46405d12179b5b8407.zip
Fix some memory allocation problems
----------------------------------------------------------------------
-rw-r--r--editors/sed.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 2b01ec7ff..05eb744a4 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -237,7 +237,7 @@ static int parse_regex_delim(const char *cmdstr, char **match, char **replace)
237 */ 237 */
238static int get_address(char *my_str, int *linenum, regex_t ** regex) 238static int get_address(char *my_str, int *linenum, regex_t ** regex)
239{ 239{
240 char *pos=my_str; 240 char *pos = my_str;
241 241
242 if (isdigit(*my_str)) { 242 if (isdigit(*my_str)) {
243 *linenum = strtol(my_str, &pos, 10); 243 *linenum = strtol(my_str, &pos, 10);
@@ -588,27 +588,33 @@ static char *add_cmd(char *cmdstr)
588 return (cmdstr); 588 return (cmdstr);
589} 589}
590 590
591static void add_cmd_str(char *cmdstr) 591static void add_cmd_str(const char *cmdstr)
592{ 592{
593#ifdef CONFIG_FEATURE_SED_EMBEDED_NEWLINE 593 char *cmdstr_expanded = strdup(cmdstr);
594 char *cmdstr_ptr = cmdstr; 594 char *cmdstr_ptr;
595 595
596#ifdef CONFIG_FEATURE_SED_EMBEDED_NEWLINE
597 cmdstr_ptr = cmdstr_expanded;
596 /* HACK: convert "\n" to match tranlated '\n' string */ 598 /* HACK: convert "\n" to match tranlated '\n' string */
597 while ((cmdstr_ptr = strstr(cmdstr_ptr, "\\n")) != NULL) { 599 while ((cmdstr_ptr = strstr(cmdstr_ptr, "\\n")) != NULL) {
598 cmdstr = xrealloc(cmdstr, strlen(cmdstr) + 2); 600 int length = strlen(cmdstr) + 2;
599 cmdstr_ptr = strstr(cmdstr, "\\n"); 601 cmdstr_expanded = realloc(cmdstr_expanded, length);
602 cmdstr_ptr = strstr(cmdstr_expanded, "\\n");
600 memmove(cmdstr_ptr + 1, cmdstr_ptr, strlen(cmdstr_ptr) + 1); 603 memmove(cmdstr_ptr + 1, cmdstr_ptr, strlen(cmdstr_ptr) + 1);
601 cmdstr_ptr[0] = '\\'; 604 cmdstr_ptr[0] = '\\';
602 cmdstr_ptr += 3; 605 cmdstr_ptr += 3;
603 } 606 }
604#endif 607#endif
608 cmdstr_ptr = cmdstr_expanded;
605 do { 609 do {
606 cmdstr = add_cmd(cmdstr); 610 cmdstr_ptr = add_cmd(cmdstr_ptr);
607 } while (cmdstr && strlen(cmdstr)); 611 } while (cmdstr_ptr && strlen(cmdstr_ptr));
612
613 free(cmdstr_expanded);
608} 614}
609 615
610 616
611static void load_cmd_file(char *filename) 617static void load_cmd_file(const char *filename)
612{ 618{
613 FILE *cmdfile; 619 FILE *cmdfile;
614 char *line; 620 char *line;
@@ -894,18 +900,15 @@ static void process_file(FILE * file)
894 /* HACK: escape newlines twice so regex can match them */ 900 /* HACK: escape newlines twice so regex can match them */
895 { 901 {
896 int offset = 0; 902 int offset = 0;
897 903 char *tmp = strchr(pattern_space + offset, '\n');
898 while (strchr(pattern_space + offset, '\n') != NULL) { 904 while ((tmp = strchr(pattern_space + offset, '\n')) != NULL) {
899 char *tmp; 905 offset = tmp - pattern_space;
900 906 pattern_space = xrealloc(pattern_space, strlen(pattern_space) + 2);
901 pattern_space = 907 tmp = pattern_space + offset;
902 xrealloc(pattern_space,
903 strlen(pattern_space) + 2);
904 tmp = strchr(pattern_space + offset, '\n');
905 memmove(tmp + 1, tmp, strlen(tmp) + 1); 908 memmove(tmp + 1, tmp, strlen(tmp) + 1);
906 tmp[0] = '\\'; 909 tmp[0] = '\\';
907 tmp[1] = 'n'; 910 tmp[1] = 'n';
908 offset = tmp - pattern_space + 2; 911 offset += 2;
909 } 912 }
910 } 913 }
911#endif 914#endif