Commit 92f12dfe authored by Geoff Simmons's avatar Geoff Simmons

simplify the check for out of workspace in URL encode

parent 0e0e007c
......@@ -81,6 +81,7 @@ url_encode(const enum encoding enc, char *restrict const buf,
const size_t inlen)
{
char *p = buf;
const char * const end = buf + buflen;
const char *alphabet = hex_alphabet[0];
AN(buf);
......@@ -93,12 +94,12 @@ url_encode(const enum encoding enc, char *restrict const buf,
for (int i = 0; i < inlen; i++) {
if (isunreserved(in[i])) {
if (p + 1 - buf > buflen)
if (p == end)
return -1;
*p++ = in[i];
}
else {
if (p + 3 - buf > buflen)
if (p + 3 > end)
return -1;
*p++ = '%';
*p++ = alphabet[(in[i] & 0xf0) >> 4];
......
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