From 1eb8244e4edb61d8ab487e8dbd1f2ece76e9aceb Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Wed, 15 Feb 2006 15:27:39 +0000 Subject: Fix bug introduced by previous delint and rename a var. From Ray. --- usr.bin/sdiff/sdiff.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'usr.bin/sdiff') 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 . @@ -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; } -- cgit v1.2.3