diff options
author | Vincent Labrecque <vincent@cvs.openbsd.org> | 2003-11-09 00:25:56 +0000 |
---|---|---|
committer | Vincent Labrecque <vincent@cvs.openbsd.org> | 2003-11-09 00:25:56 +0000 |
commit | 813dcba5d75c94ce75a82c86aa8f5bc63bb44042 (patch) | |
tree | 4829800989383e77c4310bd65bdfdbe4131ffe90 | |
parent | 84e85ae9e0d3c795f53a5f7c4a9b1c0f96a55d8e (diff) |
proper test for circular list traversal, and nul-terminate strings for
safety.
-rw-r--r-- | usr.bin/mg/region.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/usr.bin/mg/region.c b/usr.bin/mg/region.c index d91b16e5139..58595cb52ff 100644 --- a/usr.bin/mg/region.c +++ b/usr.bin/mg/region.c @@ -1,4 +1,4 @@ -/* $OpenBSD: region.c,v 1.12 2003/05/20 03:08:55 cloder Exp $ */ +/* $OpenBSD: region.c,v 1.13 2003/11/09 00:25:55 vincent Exp $ */ /* * Region based commands. @@ -323,13 +323,12 @@ region_get_data(REGION *reg, char *buf, int len) int i, off; LINE *lp; - i = 0; off = reg->r_offset; lp = reg->r_linep; - while (i < len) { + for (i = 0; i < len; i++) { if (off == llength(lp)) { lp = lforw(lp); - if (lp == curwp->w_linep) + if (lp == curbp->b_linep) break; off = 0; buf[i] = '\n'; @@ -337,8 +336,8 @@ region_get_data(REGION *reg, char *buf, int len) buf[i] = lgetc(lp, off); off++; } - i++; } + buf[i] = '\0'; return i; } @@ -347,7 +346,7 @@ region_put_data(const char *buf, int len) { int i; - for (i = 0; i < len; i++) { + for (i = 0; buf[i]; i++) { if (buf[i] == '\n') lnewline(); else @@ -355,5 +354,3 @@ region_put_data(const char *buf, int len) } return 0; } - - |