summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--isisd/isis_misc.c42
-rw-r--r--lib/sbuf.c7
-rw-r--r--lib/termtable.c9
-rw-r--r--lib/vty.c4
4 files changed, 20 insertions, 42 deletions
diff --git a/isisd/isis_misc.c b/isisd/isis_misc.c
index 0a42adea3..d4c38efaf 100644
--- a/isisd/isis_misc.c
+++ b/isisd/isis_misc.c
@@ -23,6 +23,7 @@
#include <zebra.h>
+#include "printfrr.h"
#include "stream.h"
#include "vty.h"
#include "hash.h"
@@ -511,42 +512,14 @@ void zlog_dump_data(void *data, int len)
return;
}
-static char *qasprintf(const char *format, va_list ap)
-{
- va_list aq;
- va_copy(aq, ap);
-
- int size = 0;
- char *p = NULL;
-
- size = vsnprintf(p, size, format, ap);
-
- if (size < 0) {
- va_end(aq);
- return NULL;
- }
-
- size++;
- p = XMALLOC(MTYPE_TMP, size);
-
- size = vsnprintf(p, size, format, aq);
- va_end(aq);
-
- if (size < 0) {
- XFREE(MTYPE_TMP, p);
- return NULL;
- }
-
- return p;
-}
-
void log_multiline(int priority, const char *prefix, const char *format, ...)
{
+ char shortbuf[256];
va_list ap;
char *p;
va_start(ap, format);
- p = qasprintf(format, ap);
+ p = asnprintfrr(MTYPE_TMP, shortbuf, sizeof(shortbuf), format, ap);
va_end(ap);
if (!p)
@@ -558,16 +531,18 @@ void log_multiline(int priority, const char *prefix, const char *format, ...)
zlog(priority, "%s%s", prefix, line);
}
- XFREE(MTYPE_TMP, p);
+ if (p != shortbuf)
+ XFREE(MTYPE_TMP, p);
}
void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...)
{
+ char shortbuf[256];
va_list ap;
char *p;
va_start(ap, format);
- p = qasprintf(format, ap);
+ p = asnprintfrr(MTYPE_TMP, shortbuf, sizeof(shortbuf), format, ap);
va_end(ap);
if (!p)
@@ -579,7 +554,8 @@ void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...)
vty_out(vty, "%s%s\n", prefix, line);
}
- XFREE(MTYPE_TMP, p);
+ if (p != shortbuf)
+ XFREE(MTYPE_TMP, p);
}
void vty_out_timestr(struct vty *vty, time_t uptime)
diff --git a/lib/sbuf.c b/lib/sbuf.c
index 03a2be3e0..c04af153b 100644
--- a/lib/sbuf.c
+++ b/lib/sbuf.c
@@ -22,6 +22,7 @@
*/
#include <zebra.h>
+#include "printfrr.h"
#include "sbuf.h"
#include "memory.h"
@@ -68,7 +69,7 @@ void sbuf_push(struct sbuf *buf, int indent, const char *format, ...)
written1 = indent;
va_start(args, format);
- written2 = vsnprintf(NULL, 0, format, args);
+ written2 = vsnprintfrr(NULL, 0, format, args);
va_end(args);
new_size = buf->size;
@@ -92,8 +93,8 @@ void sbuf_push(struct sbuf *buf, int indent, const char *format, ...)
buf->pos = buf->size;
va_start(args, format);
- written = vsnprintf(buf->buf + buf->pos, buf->size - buf->pos, format,
- args);
+ written = vsnprintfrr(buf->buf + buf->pos, buf->size - buf->pos,
+ format, args);
va_end(args);
if (written >= 0)
diff --git a/lib/termtable.c b/lib/termtable.c
index 01468b820..b59c1118f 100644
--- a/lib/termtable.c
+++ b/lib/termtable.c
@@ -20,6 +20,7 @@
#include <zebra.h>
#include <stdio.h>
+#include "printfrr.h"
#include "memory.h"
#include "termtable.h"
@@ -134,6 +135,7 @@ static struct ttable_cell *ttable_insert_row_va(struct ttable *tt, int i,
{
assert(i >= -1 && i < tt->nrows);
+ char shortbuf[256];
char *res, *orig, *section;
struct ttable_cell *row;
int col = 0;
@@ -158,9 +160,7 @@ static struct ttable_cell *ttable_insert_row_va(struct ttable *tt, int i,
/* CALLOC a block of cells */
row = XCALLOC(MTYPE_TTABLE, tt->ncols * sizeof(struct ttable_cell));
- res = NULL;
- vasprintf(&res, format, ap);
-
+ res = vasnprintfrr(MTYPE_TMP, shortbuf, sizeof(shortbuf), format, ap);
orig = res;
while (res && col < tt->ncols) {
@@ -170,7 +170,8 @@ static struct ttable_cell *ttable_insert_row_va(struct ttable *tt, int i,
col++;
}
- free(orig);
+ if (orig != shortbuf)
+ XFREE(MTYPE_TMP, orig);
/* insert row */
if (i == -1 || i == tt->nrows)
diff --git a/lib/vty.c b/lib/vty.c
index e306e69b8..fee585d5c 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -105,8 +105,8 @@ void vty_frame(struct vty *vty, const char *format, ...)
va_list args;
va_start(args, format);
- vsnprintf(vty->frame + vty->frame_pos,
- sizeof(vty->frame) - vty->frame_pos, format, args);
+ vsnprintfrr(vty->frame + vty->frame_pos,
+ sizeof(vty->frame) - vty->frame_pos, format, args);
vty->frame_pos = strlen(vty->frame);
va_end(args);
}