=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sdiff/sdiff.c,v retrieving revision 1.14 retrieving revision 1.15 diff -c -r1.14 -r1.15 *** src/usr.bin/sdiff/sdiff.c 2006/02/15 06:58:06 1.14 --- src/usr.bin/sdiff/sdiff.c 2006/02/15 15:27:38 1.15 *************** *** 1,4 **** ! /* $OpenBSD: sdiff.c,v 1.14 2006/02/15 06:58:06 otto Exp $ */ /* * Written by Raymond Lai . --- 1,4 ---- ! /* $OpenBSD: sdiff.c,v 1.15 2006/02/15 15:27:38 otto Exp $ */ /* * Written by Raymond Lai . *************** *** 682,688 **** { /* Length of string in previous run. */ static size_t offset = 0; ! size_t newlen; /* * String from previous run. Compared to *s to see if we are * dealing with the same string. If so, we can use offset. --- 682,688 ---- { /* Length of string in previous run. */ static size_t offset = 0; ! 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,738 **** oldstr = *s; } ! /* Length = strlen(*s) + \n + strlen(append) + '\0'. */ ! newlen = offset + 1 + strlen(append) + 1; /* Resize *s to fit new string. */ ! newstr = realloc(*s, newlen); if (newstr == NULL) err(2, "astrcat"); *s = newstr; /* Concatenate. */ ! strlcpy(*s + offset, "\n", newlen - offset); /* Store generated string's values. */ ! offset = newlen - 1; oldstr = *s; } --- 719,741 ---- oldstr = *s; } ! /* Size = strlen(*s) + \n + strlen(append) + '\0'. */ ! newsiz = offset + 1 + strlen(append) + 1; /* Resize *s to fit new string. */ ! newstr = realloc(*s, newsiz); if (newstr == NULL) err(2, "astrcat"); *s = newstr; + /* *s + offset should be end of string. */ /* Concatenate. */ ! 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 = newsiz - 1; oldstr = *s; }