Commit d17f5740 authored by Geoff Simmons's avatar Geoff Simmons

Revert "change the encoder interface -- encoders always append the null byte,"

This reverts commit 1aa6c288.

The wb interface adds a null byte, so we were getting two of them. Going
back to the requirement that the caller of an encoder adds a null
byte, which means that the blob.encode() method must do so as well.
parent bd97330f
......@@ -182,7 +182,6 @@ base64_encode(const enum encoding enc, char *restrict const buf,
}
assert(outlen > 0);
*p++ = '\0';
return p - buf;
}
......
......@@ -134,7 +134,6 @@ hex_encode(const enum encoding enc, char *restrict const buf,
*p++ = alphabet[in[i] & 0x0f];
}
*p++ = '\0';
return p - buf;
}
......
......@@ -48,7 +48,6 @@ id_encode(const enum encoding enc, char *restrict const buf,
return 0;
memcpy(buf, in, inlen);
buf[inlen] = '\0';
return inlen;
}
......
......@@ -270,6 +270,7 @@ vmod_blob_encode(VRT_CTX, struct vmod_blobcode_blob *b, VCL_ENUM encs)
AZ(pthread_mutex_lock(&b->lock));
if (b->encoding[enc] == NULL) {
ssize_t len;
switch(enc) {
case IDENTITY:
len = b->blob.len + 1;
......@@ -296,15 +297,16 @@ vmod_blob_encode(VRT_CTX, struct vmod_blobcode_blob *b, VCL_ENUM encs)
if (b->encoding[enc] == NULL)
ERRNOMEM(ctx, "cannot encode");
else {
len = encode(enc,
(void *) b->encoding[enc],
len, b->blob.priv,
b->blob.len);
const char *s = b->encoding[enc];
len = encode(enc, (void *) s, len,
b->blob.priv, b->blob.len);
assert(len >= 0);
if (len == 0) {
free((void *) b->encoding[enc]);
free((void *) s);
b->encoding[enc] = "";
}
else
*((char *)s + len) = '\0';
}
}
}
......
......@@ -60,9 +60,8 @@
*
* The regions pointed to by buf and in MUST NOT overlap (this is the
* contract imposed by restrict).
* An encoder SHALL append the terminating null byte if the length of
* the encoding is greater than 0; if the length is 0, the encoder
* SHALL NOT write the null byte.
* An encoder SHALL NOT append the terminating null byte (this must
* be done by the caller).
*
* Returns:
* -1, if there is insufficient space at buf, *including* space for the
......
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