From 9aeb8b2faa27d4e2e415b39cdcd7cd4bb375790d Mon Sep 17 00:00:00 2001 From: markw Date: Fri, 20 Apr 2001 23:41:44 +0000 Subject: Fixed a buglet where an extra newline was being added after an insert command in some cases. git-svn-id: svn://busybox.net/trunk/busybox@2395 69ca8d6d-28ef-0310-b511-8ec308f3f277 --- sed.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'sed.c') diff --git a/sed.c b/sed.c index 07e3a3e30..1342a6643 100644 --- a/sed.c +++ b/sed.c @@ -333,17 +333,20 @@ static int parse_edit_cmd(struct sed_cmd *sed_cmd, const char *editstr) } out: - ptr[idx] = '\n'; - ptr[idx+1] = 0; - /* this accounts for discrepancies between the modified string and the * original string passed in to this function */ idx += slashes_eaten; - /* this accounts for the fact that A) we started at index 3, not at index - * 0 and B) that we added an extra '\n' at the end (if you think the next - * line should read 'idx += 4' remember, arrays are zero-based) */ - idx += 3; + /* figure out if we need to add a newline */ + if (ptr[idx-1] != '\n') { + ptr[idx] = '\n'; + idx++; + } + + /* terminate string */ + ptr[idx]= 0; + /* adjust for opening 2 chars [aic]\ */ + idx += 2; return idx; } -- cgit v1.2.3-55-g6feb