Commit 3e74a3e5 authored by Nils Goroll's avatar Nils Goroll

rename maxlen to buflen to clarify that it is the length of buf

parent 9f8d9342
......@@ -56,7 +56,7 @@ base64_decode_l(size_t l)
static inline int
decode(char *restrict *restrict dest, char *restrict const buf,
const size_t maxlen, unsigned u, const int n)
const size_t buflen, unsigned u, const int n)
{
char *d;
......@@ -64,7 +64,7 @@ decode(char *restrict *restrict dest, char *restrict const buf,
return -1;
d = *dest;
for (int i = 0; i < n - 1; i++) {
if (d == buf + maxlen)
if (d == buf + buflen)
return -1;
*d++ = (u >> 16) & 0xff;
u <<= 8;
......@@ -75,7 +75,7 @@ decode(char *restrict *restrict dest, char *restrict const buf,
ssize_t
base64_encode(const enum encoding enc, char *restrict const buf,
const size_t maxlen, const char *restrict const inbuf,
const size_t buflen, const char *restrict const inbuf,
const size_t inlength)
{
const struct b64_alphabet *alpha = &b64_alphabet[enc];
......@@ -87,8 +87,8 @@ base64_encode(const enum encoding enc, char *restrict const buf,
AN(alpha);
if (in == NULL || inlength == 0)
return 0;
if ((enc != BASE64URLNOPAD && maxlen < base64_encode_l(inlength))
|| maxlen < base64nopad_encode_l(inlength))
if ((enc != BASE64URLNOPAD && buflen < base64_encode_l(inlength))
|| buflen < base64nopad_encode_l(inlength))
return -1;
while (end - in >= 3) {
......@@ -115,13 +115,13 @@ base64_encode(const enum encoding enc, char *restrict const buf,
}
}
}
assert(p >= buf && p - buf <= maxlen);
assert(p >= buf && p - buf <= buflen);
return p - buf;
}
ssize_t
base64_decode(const enum encoding dec, char *restrict const buf,
const size_t maxlen, const char *restrict const p, va_list ap)
const size_t buflen, const char *restrict const p, va_list ap)
{
const struct b64_alphabet *alpha = &b64_alphabet[dec];
char *dest = buf;
......@@ -157,7 +157,7 @@ base64_decode(const enum encoding dec, char *restrict const buf,
break;
}
if (n == 4) {
if (decode(&dest, buf, maxlen, u, n-term) < 0) {
if (decode(&dest, buf, buflen, u, n-term) < 0) {
errno = ENOMEM;
return -1;
}
......@@ -168,7 +168,7 @@ base64_decode(const enum encoding dec, char *restrict const buf,
if (n) {
if (!alpha->padding)
u <<= 6 * (4 - n);
if (decode(&dest, buf, maxlen, u, n-term) < 0) {
if (decode(&dest, buf, buflen, u, n-term) < 0) {
errno = ENOMEM;
return -1;
}
......
......@@ -74,7 +74,7 @@ hex2byte(const unsigned char hi, const unsigned char lo)
ssize_t
hex_encode(const enum encoding enc, char *restrict const buf,
const size_t maxlen, const char *restrict const in,
const size_t buflen, const char *restrict const in,
const size_t inlen)
{
char *p = buf;
......@@ -84,7 +84,7 @@ hex_encode(const enum encoding enc, char *restrict const buf,
assert(enc == HEXUC || enc == HEXLC);
if (in == NULL || inlen == 0)
return 0;
if (maxlen < hex_encode_l(inlen))
if (buflen < hex_encode_l(inlen))
return -1;
if (enc != HEXLC)
......@@ -100,7 +100,7 @@ hex_encode(const enum encoding enc, char *restrict const buf,
ssize_t
hex_decode(const enum encoding dec, char *restrict const buf,
const size_t maxlen, const char *restrict const p, va_list ap)
const size_t buflen, const char *restrict const p, va_list ap)
{
char *dest = buf;
unsigned char extranib = 0;
......@@ -132,7 +132,7 @@ hex_decode(const enum encoding dec, char *restrict const buf,
errno = EINVAL;
return -1;
}
if ((len+1) >> 1 > maxlen) {
if ((len+1) >> 1 > buflen) {
errno = ENOMEM;
return -1;
}
......@@ -151,6 +151,6 @@ hex_decode(const enum encoding dec, char *restrict const buf,
}
extranib = *s;
}
assert(dest <= buf + maxlen);
assert(dest <= buf + buflen);
return dest - buf;
}
......@@ -48,13 +48,13 @@ id_decode_l(size_t l)
ssize_t
id_encode(const enum encoding enc, char *restrict const buf,
const size_t maxlen, const char *restrict const in,
const size_t buflen, const char *restrict const in,
const size_t inlen)
{
(void) enc;
AN(buf);
if (maxlen < inlen + 1)
if (buflen < inlen + 1)
return -1;
if (in == NULL || inlen == 0)
return 0;
......@@ -65,7 +65,7 @@ id_encode(const enum encoding enc, char *restrict const buf,
ssize_t
id_decode(const enum encoding enc, char *restrict const buf,
const size_t maxlen, const char *restrict const p, va_list ap)
const size_t buflen, const char *restrict const p, va_list ap)
{
char *dest = buf;
size_t len, outlen = 0;
......@@ -78,7 +78,7 @@ id_decode(const enum encoding enc, char *restrict const buf,
if (s == NULL || *s == '\0')
continue;
len = strlen(s);
if ((outlen += len) > maxlen) {
if ((outlen += len) > buflen) {
errno = ENOMEM;
return -1;
}
......
......@@ -47,7 +47,7 @@ size_t len_f(size_t);
*
* enc: encoding enum (from parse_encoding.h)
* buf: destination of the encoded string
* maxlen: maximum length available at buf
* buflen: maximum length available at buf
* in: source of data to be encoded
* inlen: length of data to be encoded
*
......@@ -66,7 +66,7 @@ size_t len_f(size_t);
*/
typedef
ssize_t encode_f(const enum encoding enc, char *restrict const buf,
const size_t maxlen, const char *restrict const in,
const size_t buflen, const char *restrict const in,
const size_t inlen);
/*
......@@ -76,7 +76,7 @@ ssize_t encode_f(const enum encoding enc, char *restrict const buf,
*
* dec: decoding enum (from parse_encoding.h)
* buf: destination of the decoded data
* maxlen: maximum length available at buf
* buflen: maximum length available at buf
* p, ap: strings obtained from a VCL STRING_LIST
*
* The regions pointed to by buf and any of the strings in p or ap MUST
......@@ -93,7 +93,7 @@ ssize_t encode_f(const enum encoding enc, char *restrict const buf,
*/
typedef
ssize_t decode_f(const enum encoding dec, char *restrict const buf,
const size_t maxlen, const char *restrict const p, va_list ap);
const size_t buflen, const char *restrict const p, va_list ap);
/* id.c */
len_f id_encode_l;
......
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