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