Commit 22342600 authored by Geoff Simmons's avatar Geoff Simmons

simplify id_decode()

parent cf73bad4
......@@ -28,6 +28,7 @@
#include <string.h>
#include <errno.h>
#include <stdint.h>
#include "vmod_blobcode.h"
......@@ -69,23 +70,24 @@ id_decode(const enum encoding enc,
ssize_t n, const char *restrict const p, va_list ap)
{
char *dest = buf;
size_t len, outlen = 0;
size_t outlen = 0, c = SIZE_MAX;
(void) enc;
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 *)) {
size_t len;
if (s == NULL || *s == '\0')
continue;
len = strlen(s);
if (n >= 0) {
if (n == 0)
break;
if (len > n)
len = n;
n -= len;
}
if (len > c)
len = c;
c -= len;
if ((outlen += len) > buflen) {
errno = ENOMEM;
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