aboutsummaryrefslogtreecommitdiff
path: root/sed.c
diff options
context:
space:
mode:
authormarkw <markw@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-04-20 23:41:44 +0000
committermarkw <markw@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-04-20 23:41:44 +0000
commit9aeb8b2faa27d4e2e415b39cdcd7cd4bb375790d (patch)
treeb5893656cf9a09d97b7bc6e28617a91bfadbd298 /sed.c
parentfed8972ab1f09c3b7cfd22ea80213a2f02eb9e5a (diff)
downloadbusybox-w32-9aeb8b2faa27d4e2e415b39cdcd7cd4bb375790d.tar.gz
busybox-w32-9aeb8b2faa27d4e2e415b39cdcd7cd4bb375790d.tar.bz2
busybox-w32-9aeb8b2faa27d4e2e415b39cdcd7cd4bb375790d.zip
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
Diffstat (limited to 'sed.c')
-rw-r--r--sed.c17
1 files changed, 10 insertions, 7 deletions
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)
333 } 333 }
334 334
335out: 335out:
336 ptr[idx] = '\n';
337 ptr[idx+1] = 0;
338
339 /* this accounts for discrepancies between the modified string and the 336 /* this accounts for discrepancies between the modified string and the
340 * original string passed in to this function */ 337 * original string passed in to this function */
341 idx += slashes_eaten; 338 idx += slashes_eaten;
342 339
343 /* this accounts for the fact that A) we started at index 3, not at index 340 /* figure out if we need to add a newline */
344 * 0 and B) that we added an extra '\n' at the end (if you think the next 341 if (ptr[idx-1] != '\n') {
345 * line should read 'idx += 4' remember, arrays are zero-based) */ 342 ptr[idx] = '\n';
346 idx += 3; 343 idx++;
344 }
345
346 /* terminate string */
347 ptr[idx]= 0;
348 /* adjust for opening 2 chars [aic]\ */
349 idx += 2;
347 350
348 return idx; 351 return idx;
349} 352}