diff options
author | Miles Bader <miles@gnu.org> | 1997-02-21 00:05:01 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1997-02-21 00:05:01 +0000 |
commit | 47ae3e747c5851a1de7db65e55447ef21a68f56d (patch) | |
tree | 9e6e6140edff326b0e59edc6a63d68efbec5cabb /libshouldbeinlibc/argp-fmtstream.c | |
parent | caba2b9428e985565b3587e39009c0f12aa6891d (diff) |
(__argp_fmtstream_update):
Account for case where NEXTLINE points one past the end of the active
buffer.
Diffstat (limited to 'libshouldbeinlibc/argp-fmtstream.c')
-rw-r--r-- | libshouldbeinlibc/argp-fmtstream.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libshouldbeinlibc/argp-fmtstream.c b/libshouldbeinlibc/argp-fmtstream.c index c7203dea..ab2e870a 100644 --- a/libshouldbeinlibc/argp-fmtstream.c +++ b/libshouldbeinlibc/argp-fmtstream.c @@ -240,7 +240,14 @@ __argp_fmtstream_update (argp_fmtstream_t fs) nextline = p; } - if (nextline - (nl + 1) < fs->wmargin) + /* Note: There are a bunch of tests below for + NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall + at the end of the buffer, and NEXTLINE is in fact empty (and so + we need not be careful to maintain its contents). */ + + if (nextline == buf + len + 1 + ? fs->end - nl < fs->wmargin + 1 + : nextline - (nl + 1) < fs->wmargin) /* The margin needs more blanks than we removed. */ if (fs->end - fs->p > fs->wmargin + 1) /* Make some space for them. */ @@ -265,7 +272,8 @@ __argp_fmtstream_update (argp_fmtstream_t fs) the next word. */ *nl++ = '\n'; - if (nextline - nl >= fs->wmargin) + if (nextline - nl >= fs->wmargin + || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin)) /* Add blanks up to the wrap margin column. */ for (i = 0; i < fs->wmargin; ++i) *nl++ = ' '; @@ -275,7 +283,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) /* Copy the tail of the original buffer into the current buffer position. */ - if (nl != nextline) + if (nl < nextline) memmove (nl, nextline, buf + len - nextline); len -= nextline - buf; |