Commit 1aa6c288 authored by Geoff Simmons's avatar Geoff Simmons

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

except when the encoding is the empty string
parent 2d94f811
...@@ -182,6 +182,7 @@ base64_encode(const enum encoding enc, char *restrict const buf, ...@@ -182,6 +182,7 @@ 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,6 +134,7 @@ hex_encode(const enum encoding enc, char *restrict const buf, ...@@ -134,6 +134,7 @@ 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,6 +48,7 @@ id_encode(const enum encoding enc, char *restrict const buf, ...@@ -48,6 +48,7 @@ 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;
} }
......
...@@ -60,8 +60,9 @@ ...@@ -60,8 +60,9 @@
* *
* 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 NOT append the terminating null byte (this must * An encoder SHALL append the terminating null byte if the length of
* be done by the caller). * the encoding is greater than 0; if the length is 0, the encoder
* 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