Commit cf73bad4 authored by Geoff Simmons's avatar Geoff Simmons

simplify base64_decode()

parent 31f86d26
......@@ -132,11 +132,15 @@ base64_decode(const enum encoding dec, char *restrict const buf,
char *dest = buf;
unsigned u = 0, term = 0;
int n = 0;
size_t len = SIZE_MAX;
AN(buf);
AN(alpha);
for (const char *s = p; s != vrt_magic_string_end;
if (inlen >= 0)
len = inlen;
for (const char *s = p; len > 0 && s != vrt_magic_string_end;
s = va_arg(ap, const char *)) {
if (s == NULL)
continue;
......@@ -144,7 +148,7 @@ base64_decode(const enum encoding dec, char *restrict const buf,
errno = EINVAL;
return -1;
}
while (*s && (inlen == -1 || inlen > 0)) {
while (*s && len) {
while (n < 4) {
char b = alpha->i64[(unsigned) *s++];
u <<= 6;
......@@ -158,11 +162,8 @@ base64_decode(const enum encoding dec, char *restrict const buf,
continue;
}
u |= (unsigned) b;
if (inlen != -1) {
--inlen;
if (inlen == 0)
break;
}
if (--len == 0)
break;
if (!*s)
break;
}
......@@ -172,8 +173,6 @@ base64_decode(const enum encoding dec, char *restrict const buf,
n = 0;
}
}
if (inlen != -1 && inlen == 0)
break;
}
if (n) {
if (!alpha->padding)
......
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