=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rcs/rcs.c,v retrieving revision 1.58 retrieving revision 1.59 diff -c -r1.58 -r1.59 *** src/usr.bin/rcs/rcs.c 2010/07/23 08:31:19 1.58 --- src/usr.bin/rcs/rcs.c 2010/07/23 21:46:05 1.59 *************** *** 1,4 **** ! /* $OpenBSD: rcs.c,v 1.58 2010/07/23 08:31:19 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. --- 1,4 ---- ! /* $OpenBSD: rcs.c,v 1.59 2010/07/23 21:46:05 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. *************** *** 1145,1151 **** * * Get the whole contents of revision from the RCSFILE . The * returned buffer is dynamically allocated and should be released using ! * rcs_buf_free() once the caller is done using it. */ BUF* rcs_getrev(RCSFILE *rfp, RCSNUM *frev) --- 1145,1151 ---- * * Get the whole contents of revision from the RCSFILE . The * returned buffer is dynamically allocated and should be released using ! * buf_free() once the caller is done using it. */ BUF* rcs_getrev(RCSFILE *rfp, RCSNUM *frev) *************** *** 1190,1202 **** len = rdp->rd_tlen; if (len == 0) { ! rbuf = rcs_buf_alloc(1, 0); ! rcs_buf_empty(rbuf); return (rbuf); } ! rbuf = rcs_buf_alloc(len, BUF_AUTOEXT); ! rcs_buf_append(rbuf, rdp->rd_text, len); isbranch = 0; brev = NULL; --- 1190,1202 ---- len = rdp->rd_tlen; if (len == 0) { ! rbuf = buf_alloc(1, 0); ! buf_empty(rbuf); return (rbuf); } ! rbuf = buf_alloc(len, BUF_AUTOEXT); ! buf_append(rbuf, rdp->rd_text, len); isbranch = 0; brev = NULL; *************** *** 1261,1274 **** rdp = rcs_findrev(rfp, crev); if (rdp == NULL) { ! rcs_buf_free(rbuf); return (NULL); } plen = rdp->rd_tlen; ! dlen = rcs_buf_len(rbuf); patch = rdp->rd_text; ! data = rcs_buf_release(rbuf); /* check if we have parsed this rev's deltatext */ if (rdp->rd_tlen == 0) rcs_parse_deltatexts(rfp, rdp->rd_num); --- 1261,1274 ---- rdp = rcs_findrev(rfp, crev); if (rdp == NULL) { ! buf_free(rbuf); return (NULL); } plen = rdp->rd_tlen; ! dlen = buf_len(rbuf); patch = rdp->rd_text; ! data = buf_release(rbuf); /* check if we have parsed this rev's deltatext */ if (rdp->rd_tlen == 0) rcs_parse_deltatexts(rfp, rdp->rd_num); *************** *** 1455,1470 **** if ((nextbuf = rcs_getrev(rf, nextrdp->rd_num)) == NULL) errx(1, "error getting revision"); ! newdiff = rcs_buf_alloc(64, BUF_AUTOEXT); /* calculate new diff */ (void)xasprintf(&path_tmp1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir); ! rcs_buf_write_stmp(nextbuf, path_tmp1); ! rcs_buf_free(nextbuf); (void)xasprintf(&path_tmp2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir); ! rcs_buf_write_stmp(prevbuf, path_tmp2); ! rcs_buf_free(prevbuf); diff_format = D_RCSDIFF; if (diffreg(path_tmp1, path_tmp2, newdiff, D_FORCEASCII) == D_ERROR) --- 1455,1470 ---- if ((nextbuf = rcs_getrev(rf, nextrdp->rd_num)) == NULL) errx(1, "error getting revision"); ! newdiff = buf_alloc(64, BUF_AUTOEXT); /* calculate new diff */ (void)xasprintf(&path_tmp1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir); ! buf_write_stmp(nextbuf, path_tmp1); ! buf_free(nextbuf); (void)xasprintf(&path_tmp2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir); ! buf_write_stmp(prevbuf, path_tmp2); ! buf_free(prevbuf); diff_format = D_RCSDIFF; if (diffreg(path_tmp1, path_tmp2, newdiff, D_FORCEASCII) == D_ERROR) *************** *** 2662,2670 **** if (timezone_flag != NULL) rcs_set_tz(timezone_flag, rdp, &tb); ! len = rcs_buf_len(bp); ! c = rcs_buf_get(bp); found = 0; /* Final character in buffer. */ fin = c + len - 1; --- 2662,2670 ---- if (timezone_flag != NULL) rcs_set_tz(timezone_flag, rdp, &tb); ! len = buf_len(bp); ! c = buf_get(bp); found = 0; /* Final character in buffer. */ fin = c + len - 1; *************** *** 2832,2856 **** errx(1, "rcs_expand_keywords: string truncated"); /* Concatenate everything together. */ ! tmpbuf = rcs_buf_alloc(len + strlen(expbuf), BUF_AUTOEXT); /* Append everything before keyword. */ ! rcs_buf_append(tmpbuf, rcs_buf_get(newbuf), ! start - (unsigned char *)rcs_buf_get(newbuf)); /* Append keyword. */ ! rcs_buf_append(tmpbuf, expbuf, strlen(expbuf)); /* Point c to end of keyword. */ ! c = rcs_buf_get(tmpbuf) + rcs_buf_len(tmpbuf) - 1; /* Append everything after keyword. */ ! rcs_buf_append(tmpbuf, end, ! ((unsigned char *)rcs_buf_get(newbuf) + rcs_buf_len(newbuf)) - end); /* Point fin to end of data. */ ! fin = rcs_buf_get(tmpbuf) + rcs_buf_len(tmpbuf) - 1; /* Recalculate new length. */ ! len = rcs_buf_len(tmpbuf); /* tmpbuf is now ready, free old newbuf if allocated here. */ if (newbuf != bp) ! rcs_buf_free(newbuf); newbuf = tmpbuf; } } --- 2832,2856 ---- errx(1, "rcs_expand_keywords: string truncated"); /* Concatenate everything together. */ ! tmpbuf = buf_alloc(len + strlen(expbuf), BUF_AUTOEXT); /* Append everything before keyword. */ ! buf_append(tmpbuf, buf_get(newbuf), ! start - (unsigned char *)buf_get(newbuf)); /* Append keyword. */ ! buf_append(tmpbuf, expbuf, strlen(expbuf)); /* Point c to end of keyword. */ ! c = buf_get(tmpbuf) + buf_len(tmpbuf) - 1; /* Append everything after keyword. */ ! buf_append(tmpbuf, end, ! ((unsigned char *)buf_get(newbuf) + buf_len(newbuf)) - end); /* Point fin to end of data. */ ! fin = buf_get(tmpbuf) + buf_len(tmpbuf) - 1; /* Recalculate new length. */ ! len = buf_len(tmpbuf); /* tmpbuf is now ready, free old newbuf if allocated here. */ if (newbuf != bp) ! buf_free(newbuf); newbuf = tmpbuf; } } *************** *** 2880,2888 **** if (rdp->rd_text != NULL) xfree(rdp->rd_text); ! len = rcs_buf_len(bp); ! dtext = rcs_buf_release(bp); bp = NULL; if (len != 0) { rdp->rd_text = xmalloc(len); rdp->rd_tlen = len; --- 2880,2889 ---- if (rdp->rd_text != NULL) xfree(rdp->rd_text); ! len = buf_len(bp); ! dtext = buf_release(bp); bp = NULL; + if (len != 0) { rdp->rd_text = xmalloc(len); rdp->rd_tlen = len;