Commit c47dcc40 authored by Nils Goroll's avatar Nils Goroll

set ENOMEM consistently (I hope everywhere)

parent c1dc185c
...@@ -84,8 +84,10 @@ hex_encode(const enum encoding enc, char *restrict const buf, ...@@ -84,8 +84,10 @@ hex_encode(const enum encoding enc, char *restrict const buf,
assert(enc == HEXUC || enc == HEXLC); assert(enc == HEXUC || enc == HEXLC);
if (in == NULL || inlen == 0) if (in == NULL || inlen == 0)
return 0; return 0;
if (buflen < hex_encode_l(inlen)) if (buflen < hex_encode_l(inlen)) {
errno = ENOMEM;
return -1; return -1;
}
if (enc != HEXLC) if (enc != HEXLC)
alphabet = hex_alphabet[1]; alphabet = hex_alphabet[1];
......
...@@ -55,8 +55,10 @@ id_encode(const enum encoding enc, char *restrict const buf, ...@@ -55,8 +55,10 @@ id_encode(const enum encoding enc, char *restrict const buf,
(void) enc; (void) enc;
AN(buf); AN(buf);
if (buflen < inlen + 1) if (buflen < inlen + 1) {
errno = ENOMEM;
return -1; return -1;
}
if (in == NULL || inlen == 0) if (in == NULL || inlen == 0)
return 0; return 0;
......
...@@ -95,13 +95,17 @@ url_encode(const enum encoding enc, char *restrict const buf, ...@@ -95,13 +95,17 @@ url_encode(const enum encoding enc, char *restrict const buf,
for (int i = 0; i < inlen; i++) { for (int i = 0; i < inlen; i++) {
if (isunreserved(in[i])) { if (isunreserved(in[i])) {
if (p == end) if (p == end) {
errno = ENOMEM;
return -1; return -1;
}
*p++ = in[i]; *p++ = in[i];
} }
else { else {
if (p + 3 > end) if (p + 3 > end) {
errno = ENOMEM;
return -1; return -1;
}
*p++ = '%'; *p++ = '%';
*p++ = alphabet[(in[i] & 0xf0) >> 4]; *p++ = alphabet[(in[i] & 0xf0) >> 4];
*p++ = alphabet[in[i] & 0x0f]; *p++ = alphabet[in[i] & 0x0f];
......
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