summaryrefslogtreecommitdiff
path: root/lib/printf.c
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2016-12-07 15:36:15 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2016-12-07 15:54:19 +0100
commit77234bbbde6bc328871af695e4450e6773adbafa (patch)
tree0ed60508b521eba6af6c4b852df09fdf8c659154 /lib/printf.c
parentb94e5e58dbd33f4d2b9d721c51a9c8c4d8f77bea (diff)
Basic flow specification support (RFC 5575)
Add flow4/flow6 network and rt-table type and operations, config grammar and static protocol support. Squashed flowspec branch from Pavel Tvrdik.
Diffstat (limited to 'lib/printf.c')
-rw-r--r--lib/printf.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/printf.c b/lib/printf.c
index 1632b5f3..8e3cbbcf 100644
--- a/lib/printf.c
+++ b/lib/printf.c
@@ -467,6 +467,10 @@ int
buffer_vprint(buffer *buf, const char *fmt, va_list args)
{
int i = bvsnprintf((char *) buf->pos, buf->end - buf->pos, fmt, args);
+
+ if ((i < 0) && (buf->pos < buf->end))
+ *buf->pos = 0;
+
buf->pos = (i >= 0) ? (buf->pos + i) : buf->end;
return i;
}
@@ -478,9 +482,12 @@ buffer_print(buffer *buf, const char *fmt, ...)
int i;
va_start(args, fmt);
- i=bvsnprintf((char *) buf->pos, buf->end - buf->pos, fmt, args);
+ i = bvsnprintf((char *) buf->pos, buf->end - buf->pos, fmt, args);
va_end(args);
+ if ((i < 0) && (buf->pos < buf->end))
+ *buf->pos = 0;
+
buf->pos = (i >= 0) ? (buf->pos + i) : buf->end;
return i;
}
@@ -489,13 +496,13 @@ void
buffer_puts(buffer *buf, const char *str)
{
byte *bp = buf->pos;
- byte *be = buf->end;
+ byte *be = buf->end - 1;
while (bp < be && *str)
*bp++ = *str++;
- if (bp < be)
+ if (bp <= be)
*bp = 0;
- buf->pos = bp;
+ buf->pos = (bp < be) ? bp : buf->end;
}