summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
authorVincent Labrecque <vincent@cvs.openbsd.org>2002-07-25 16:40:58 +0000
committerVincent Labrecque <vincent@cvs.openbsd.org>2002-07-25 16:40:58 +0000
commite6ad39795b6d3b1a3e370a129b1af72fa18fe62d (patch)
treef190ddb669d47804e6c4241f8d8670dd05967c08 /usr.bin/mg
parent4ddef896553dfa013b86c100b72f54645767fa38 (diff)
use vasprintf() instead of vsnprintf + malloc + vsnprintf hack;idea from deraadt
ok art
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/buffer.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c
index dbb226e7ee8..1d341b462ae 100644
--- a/usr.bin/mg/buffer.c
+++ b/usr.bin/mg/buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buffer.c,v 1.29 2002/06/19 22:05:58 vincent Exp $ */
+/* $OpenBSD: buffer.c,v 1.30 2002/07/25 16:40:57 vincent Exp $ */
/*
* Buffer handling.
@@ -357,24 +357,16 @@ addlinef(BUFFER *bp, char *fmt, ...)
{
va_list ap;
LINE *lp;
- int ntext;
- char dummy[1];
+ if ((lp = lalloc(0)) == NULL)
+ return (FALSE);
va_start(ap, fmt);
- ntext = vsnprintf(dummy, 1, fmt, ap);
- if (ntext == -1) {
+ if (vasprintf(&lp->l_text, fmt, ap) == -1) {
+ lfree(lp);
va_end(ap);
- return FALSE;
+ return (FALSE);
}
- ntext++;
- if ((lp = lalloc(ntext)) == NULL) {
- va_end(ap);
- return FALSE;
- }
- va_end(ap);
- va_start(ap, fmt);
- vsnprintf(lp->l_text, ntext, fmt, ap);
- lp->l_used--;
+ lp->l_used = strlen(lp->l_text);
va_end(ap);
bp->b_linep->l_bp->l_fp = lp; /* Hook onto the end */