Commit 22342600 authored by Geoff Simmons's avatar Geoff Simmons

simplify id_decode()

parent cf73bad4
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <stdint.h>
#include "vmod_blobcode.h" #include "vmod_blobcode.h"
...@@ -69,23 +70,24 @@ id_decode(const enum encoding enc, ...@@ -69,23 +70,24 @@ id_decode(const enum encoding enc,
ssize_t n, const char *restrict const p, va_list ap) ssize_t n, const char *restrict const p, va_list ap)
{ {
char *dest = buf; char *dest = buf;
size_t len, outlen = 0; size_t outlen = 0, c = SIZE_MAX;
(void) enc; (void) enc;
AN(buf); AN(buf);
for (const char *s = p; s != vrt_magic_string_end; if (n >= 0)
c = n;
for (const char *s = p; c > 0 && s != vrt_magic_string_end;
s = va_arg(ap, const char *)) { s = va_arg(ap, const char *)) {
size_t len;
if (s == NULL || *s == '\0') if (s == NULL || *s == '\0')
continue; continue;
len = strlen(s); len = strlen(s);
if (n >= 0) { if (len > c)
if (n == 0) len = c;
break; c -= len;
if (len > n)
len = n;
n -= len;
}
if ((outlen += len) > buflen) { if ((outlen += len) > buflen) {
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment