summaryrefslogtreecommitdiff
path: root/usr.bin/sdiff/sdiff.c
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2006-02-15 15:27:39 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2006-02-15 15:27:39 +0000
commit1eb8244e4edb61d8ab487e8dbd1f2ece76e9aceb (patch)
tree66d2cdcd831d8263f067cb2994cd187d2bfab41d /usr.bin/sdiff/sdiff.c
parent27bbdeed3a95c32e4357f3c8d48eae4c806c6c53 (diff)
Fix bug introduced by previous delint and rename a var. From Ray.
Diffstat (limited to 'usr.bin/sdiff/sdiff.c')
-rw-r--r--usr.bin/sdiff/sdiff.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/usr.bin/sdiff/sdiff.c b/usr.bin/sdiff/sdiff.c
index f5f829acc1c..69a87be93d1 100644
--- a/usr.bin/sdiff/sdiff.c
+++ b/usr.bin/sdiff/sdiff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sdiff.c,v 1.14 2006/02/15 06:58:06 otto Exp $ */
+/* $OpenBSD: sdiff.c,v 1.15 2006/02/15 15:27:38 otto Exp $ */
/*
* Written by Raymond Lai <ray@cyth.net>.
@@ -682,7 +682,7 @@ astrcat(char **s, const char *append)
{
/* Length of string in previous run. */
static size_t offset = 0;
- size_t newlen;
+ size_t newsiz;
/*
* String from previous run. Compared to *s to see if we are
* dealing with the same string. If so, we can use offset.
@@ -719,20 +719,23 @@ astrcat(char **s, const char *append)
oldstr = *s;
}
- /* Length = strlen(*s) + \n + strlen(append) + '\0'. */
- newlen = offset + 1 + strlen(append) + 1;
+ /* Size = strlen(*s) + \n + strlen(append) + '\0'. */
+ newsiz = offset + 1 + strlen(append) + 1;
/* Resize *s to fit new string. */
- newstr = realloc(*s, newlen);
+ newstr = realloc(*s, newsiz);
if (newstr == NULL)
err(2, "astrcat");
*s = newstr;
+ /* *s + offset should be end of string. */
/* Concatenate. */
- strlcpy(*s + offset, "\n", newlen - offset);
+ strlcpy(*s + offset, "\n", newsiz - offset);
+ strlcat(*s + offset, append, newsiz - offset);
+ /* New string length should be exactly newsiz - 1 characters. */
/* Store generated string's values. */
- offset = newlen - 1;
+ offset = newsiz - 1;
oldstr = *s;
}